×

Different Kinds of Boxes in Latex

Different Kinds of Boxes in Latex

A box is an object which is treated as a character in LaTex. A box can never be broken or split into multiple pages or lines. We have three kinds of boxes in LaTex, which are as follows:

  • LR – The contents of this box are rendered from left to right (LR = Left-Right).
  • Par – These kinds of boxes contain several lines that are typeset in paragraph mode like the normal text. Paragraphs can be put one on top of the other. We can control the width of the paragraph.
  • Rule – A rule is generally a thick or thin line that separates different rows or columns. It is also used to separate the title from the main text.

LR Boxes

We have four types of boxes under this category. These four varieties of boxes are generated by the following commands.

fbox{texts}

mbox{texts}

framebox[width][pos]{texts}

makebox[width][pos]{texts}

The commands that start with letter ‘f’ will render a rectangular frame inside which the texts will reside. This rectangular frame will be missing in the commands starting with another letter. The following example illustrates the same.

documentclass{article}
usepackage[utf8]{inputenc}
egin{document}
fbox{inside the fbox}\[7pt]
mbox{inside the mbox}\[7pt]
makebox[5cm][c]{inside the make box}\[7pt]
framebox[5cm][l]{inside the frame box}
end{document}

Output:

The options provided in square brackets for the framebox and makebox commands are optional. Apart from ‘l’ (left) and ‘c’ (centre), we can also use ‘r’ (right) or ‘s’ (stretch). Option ‘r’ will put the text on the right side of the box and the ‘s’ option will stretch the texts from left to right side of the box. Must try these options to understand their effect. The default option is ‘c’.

Please note that the makebox or mbox commands also render boxes. The only difference is they do not render the rectangular frame. The command fbox puts a rectangular frame around the texts. mbox also does the same thing, but the frame will be missing.

The first optional argument width can have four-length commands: width, depth, height, and otalheight.

The depth and height commands control the length below and above the baseline. The otalheight command is the sum of depth and height. The width command deals with the width of the box. The following snapshot will make the concept even more clear.

The dotted horizontal line is the baseline.

documentclass{article}
usepackage[utf8]{inputenc}
egin{document}
framebox[2width]{inside the frame box}
end{document}

Output:

We can also control the appearance of the frames.

The fboxrule parameter sets the width of the lines which comprise the frame. The default value is 0.4pt for all the classes.

Another parameter is fboxsep. This command controls the space between contents and the edge of the frame. The default value is 3pt.

It is quite obvious that these commands can only come into the picture when we are using commands which render a frame (fbox or framebox).

Let us understand the functionality of the fboxrule and fboxsep parameters.

documentclass{article}
usepackage[utf8]{inputenc}
egin{document}
setlengthfboxrule{6pt}setlengthfboxsep{6mm}
fbox{We are learning about various commands to deal with the frame design.}
end{document}

Output:

We have used setlength to set the values for fboxrule and fboxsep.

Not only this, we can even lower or raise the box. To do so, we use the aisebox command. The general syntax of the command is:

aisebox{lift}[depth][height]{texts}

The second and the third arguments are optional. The lift parameter pushes the text above or below the baseline as per the value given by us. Consider the following code.

documentclass{article}
usepackage[utf8]{inputenc}
egin{document}

aisebox{1.5ex}{Up} baseline

aisebox{-1.5ex}{down} baseline

aisebox{1.5ex}{Up} baseline

aisebox{-1.5ex}{down} baseline
end{document}

Output:

The value 1.5ex does the lifting in the upward direction whereas, the negative value deals with the downward direction. We can also use length commands (dept, height, width, otalheight) in the aisebox command (observe the optional arguments).

We can even do the rotation of boxes. The demonstration is given below.

documentclass{article}
usepackage{graphicx}
egin{document}
$a_1$ 
otatebox{90}{fbox{The vertical one}}
$a_2$ 
otatebox{45}{
aisebox{height}{fbox{Positioned at $45^circ$}}}
$a_3$ 
otatebox{45}{
aisebox{-height}{fbox{This positioning is weird.}}}
$a_4$
end{document}

Output:

For the rotation we use otatebox{}{} command. The first argument of the command tells about the rotation angle. The first box is rotated by 90 degrees. Therefore, we see a vertical box. The remaining two boxes are rotated by 45 degrees. The second argument takes the text to be rotated. We have also used the aisebox command to change the positioning of the box. Observe the base position of the second and the third box. One is above the baseline, while the other is below the baseline. This is due to the usage of the height and -height commands in the arguments of the aisebox command.

Note: It is mandatory to include the graphicx package. Otherwise, the otatebox{}{} command will not work.

Paragraph Boxes

We use the parbox command to construct a paragraph box. The general syntax of the parbox command is:

parbox[pos]{width}{texts}

The pos argument is optional. The pos argument is used for positioning the text. Let us write a code using the parbox command.

documentclass{article}
egin{document}
parbox{0.5linewidth}{This paragraph is typeset using the parbox command.}
end{document}

Output:

We can see there is a line break at the word ‘parbox’ in the output. This is due to the width is set to half of the line-width. Just change the 0.5linewidth to linewidth, and then we will get the output as follows.

linewidth contains the width of the line. We can also achieve the above output using the minipage environment. Run the following code and observe the output.

documentclass{article}
egin{document}
egin{minipage}{linewidth}{This paragraph is typeset using the parbox command.}
end{minipage}
end{document}

The general syntax for the minipage environment will be:

egin{minipage}[pos]{width} … texts … end{minipage}

Here also, the pos argument is optional.

Now, we can talk about the positioning of texts. The pos argument can take the following values:

t – To place the texts at the top of the page.

b – To place the texts at the bottom.

c – This option shows the text at the center of the page (vertically centralized). This is also the default value.

s – Letter ‘s’ stands for stretch. This option will stretch the text. Therefore, the gap between the words will increase.

All these above options do the vertical positioning with respect to the text baseline.

Now, consider the following code:

documentclass{article}
egin{document}
egin{minipage}[t]{0.5linewidth}
This is the first paragraph and its width is half of the line-width. This minipage environment is quite essential in positioning of texts.
end{minipage}
egin{minipage}[b]{0.5linewidth}
This is the second paragraph and its width is half of the line-width. We must understand the usage of the different position values.
end{minipage}
end{document}

Output:

Note: The above output can also be achieved by using the parbox command.

Boxes With Specific Heights

We can even extend the minipage environment or the parbox command to include two more arguments. Thus, the general syntax of the parbox command will be:

parbox[pos][height][inner-pos]{width}{texts}

Similarly, for the minipage environment we have

egin{minipage}[pos][height][inner-pos]{width} … texts … end{minipage}.

Let us take an example to understand it better.

documentclass{article}
egin{document}
egin{minipage}[b][4cm][t]{2cm}
The height of this minipage is 4~cm.
end{minipage}hfill
egin{minipage}[b][4cm][c]{2cm}
The height of this minipage is also 4~cm. However, it is vertically centered.
end{minipage}hfill
egin{minipage}[b][4cm][b]{2cm}
This minipage has the same height. But, it is positioned at the bottom of the page.
end{minipage}hfill
egin{minipage}[b][4cm][s]{2cm}
aselineskip 8pt plus 1pt minus 1pt
This is the last minibox of the same height. The texts in this box are stretched.
end{minipage}
end{document}

Output:

The height and width of each box are 4cm and 2cm, respectively. The hfill command provides space between the boxes. This space is the rubber length, which can shrink or stretch horizontally as per need. In the last minibox, we have used the command aselineskip. This command shows spaces between lines (observe the interline spaces in the last minipage of the output.). In our case, the interline space can reach up to as high as 9pt and as low as 7pt. Do try to generate the above output using parbox command.

Nested Box

We can do any level of nesting for the boxes. Consider the following.

documentclass{article}
egin{document}
fbox{fbox { parbox { .5linewidth} {We are inside the second box. The line-width is half of the total line-width.}}}
end{document}

Output:

Since we have nested two fbox commands, we are getting two frames.

Rule Boxes

A rule box is a rectangle filled with black color. We use the ule command to achieve the solid rectangle. The general syntax for the ule command is:

ule[lift]{width}{height}

The first argument, which is also the optional one, tells us about how much amount we need to raise the rectangle from the baseline. The second one and the third one is self-explanatory. The following code does illustrate the usage of the ule command.

documentclass{article}
egin{document}

ule{7mm}{10mm}

ule[5mm]{10mm}{7mm}
end{document}

Output:

The second rectangle, in the output, has been lifted by 5mm from the baseline. To place the rectangle below the baseline, use a negative value. We can also draw a dark horizontal line using the ule command. The following code does the same.

documentclass{article}
egin{document}

ule{5in}{.2mm}
end{document}

Output:

In the code, we have increased the width a lot as compared to the height. Hence, we got the above result.


Related Topics

Difference between Open-Source Software and Proprietary Software

The commercial software business is most terrified by the idea of open-source software, yet open-source has plenty of developers and programmers on its plate who are least intimidated by the...

3 minutes read.

Difference between SDN and NFV

1. Software Defined Networking (SDN) The aim of the SDN design is to enhance overall network performance, and by providing a dynamic and programmatically effective network setup, networks may become nimble...

3 minutes read.

Difference between Hematite and Magnetite

What are Iron ores? Iron makes up a large portion of both the Earth's outer and inner cores, making it the most prevalent element on Earth by mass, just ahead of...

3 minutes read.

Difference between ERP and SAP Software

There are different businesses running in the world. Not only large businesses, the small businesses are also need a lot of planning to run in a smooth manner. All the...

3 minutes read.

Difference between ASCII and Unicode

Introduction In this article, we are going to learn about the differences between ASCII and Unicode. We are going to study briefly about these two topics and study about major differences...

3 minutes read.

Difference between EBS and EFS

The Amazon web service provides a storage management system. There are two types of the storage management system. These are AWS EFS (Elastic File System) and AWS EBS (Elastic Block...

4 minutes read.

Difference between Research Papers and Technical Papers

What are Research Papers? Research papers are pieces of writing that document the findings of in-depth investigations on a particular topic. In most cases, they take a previously unresolved problem in...

2 minutes read.

Difference between HMO and PPO

HMO is short for Health Maintenance Organization, and PPO is short for Preferred Provider Organization. HMO and PPO are the two kinds of health insurance plans. If you want to...

6 minutes read.

Difference between .NET Core and .NET Framework

We can create the modern cloud-based software applications on popular operating systems such as Windows, Linux, and macOS using the free, open-source, .NET framework. One of the major contributions of...

3 minutes read.

Difference between Dicot and Monocot seeds

Dicot seed Dicot seeds are the seeds that comprise two embryonic leaves or cotyledons. They are also called dicotyledons. It includes one embryo with an embryo axis and two cotyledons all...

2 minutes read.

Difference between PROM and EPROM

Generally, we know that ROM (Read-Only Memory) is a memory that cannot be changed. It is a non-volatile memory, meaning that these memory chips will not be affected when the...

3 minutes read.

Difference between Need and Want

Difference between Need and Want Every living being on this planet has some materialistic necessity. Human beings, birds, animals, plants, trees, insects, bacteria and viruses; all of these want something to...

6 minutes read.

Difference between Hyperlink and Hypertext

Although they are connected, hyperlink and hypertext are very different from one another. Both are essential components of the Internet. They form the core of everything that makes up the...

3 minutes read.

Difference between Bezier Curve and B-Spline Curve

Nowadays, we all see that the use of graphics is increased. Graphics is used in all the websites, applications and also games. Ever wondered how such smooth curves are created...

3 minutes read.

Difference between Solenoid and Toroid

In this article, we are going to study about the Solenoid and Toroid. Both Solenoid and Toroid are closely related to each other, and they also have some differences. So,...

3 minutes read.

Difference between Online and Offline Marketing

What is Online Marketing? The phrase "online brand marketing" refers to a variety of online marketing and advertising strategies that brands can use to promote their goods and services. There are many...

3 minutes read.

Difference between Website and Web Application

The frontend and backend of both a website and a web application are programmed in the same programming language. They may run in browsers, they need internet access, and they...

3 minutes read.

Difference between First Angle Projection and Third Angle Projection

We use the orthographic projection technique to represent a 3D object on a 2D plane. The orthographic projection system makes use of parallel lines to transcribe 2D views of 3D...

2 minutes read.

Difference between PDCA and DMAIC

We people have a lot of problems, and we also find the solutions for the problems when we think and understand the problem. Different people understand a problem in their...

6 minutes read.

Difference between E-Commerce and M-Commerce

With the time changes, people are not interested in staying in the queue. So people are now adopting new trends like E-Commerce, M-Commerce, etc. E-Commerce is defined as the selling,...

3 minutes read.