×

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 Bone and Cartilage

Difference between Bone and Cartilage Human body is the most sophisticated creation of the nature. The body that we look in the mirror is the most complex machine as well. This...

6 minutes read.

Difference between Paging and Segmentation

What is Paging? Paging is one of the most important terms used in the operating system. Paging divides the physical memory into frames and program’s address space into identical size pages....

4 minutes read.

Difference between Wi-Fi and Cellular Network

You must have familiar with the term Wi-Fi and cellular data. These terms are used in the field of internet connections. Many times we get confused about these two things....

3 minutes read.

Difference between India and Australia

Difference between India and Australia India India is a large country in Asia Continent. A Portuguese explorer VascodeGama was the first European who reach India. He reached Calicut (India) in July 1497...

5 minutes read.

Difference between OTG and Microwave

OTG OTG’s complete form is Oven, toaster, grill. It is a mini model of a traditional oven. OTG oven is used for baking, toasting, reheating, and grilling food. It uses heated...

2 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 Visa and Passport

Traveling is an inevitable part of life. People travel to distant areas for work, jobs, studies, etc. Traveling helps us in having a practical experience of places, cities, countries, etc....

4 minutes read.

Difference Between Has and Have

Difference Between Has and Have Sometimes, we all face the troubles and confusion in English even in the very simplest of grammars. But it’s completely fine in the process of learning. In...

5 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 Memory Mapped IO and IO Mapped IO with reference to 8085 Microprocessor

The microprocessor is unable to act independently; therefore, it must be connected to memory, additional peripherals, or IO devices. Interfacing is the term for this connecting. There are two methods to...

3 minutes read.

Difference between npm and yarn

Package managers like npm and yarn assist in managing a project's dependencies. A dependency is a component of code that a project needs to function properly. They are necessary because...

3 minutes read.

Difference between UART and USART

Universal Asynchronous Receiver Transmitter is referred to as UART. Universal Synchronous Asynchronous Receiver Transmitter is referred to as USART. They are merely a piece of hardware that transforms parallel data...

3 minutes read.

Anxiety vs Depression

Difference between Anxiety and Depression The terms anxiety and depression are used by people very casually, but these terms have a very serious outcome. Both explain an emotion of a person....

8 minutes read.

Difference between Backtracking and Recursion

What is Backtracking? Backtracking is a process that helps to solve the problem recursively. In other words, backtracking is an algorithm that solves the problem. It uses a recursive function to...

6 minutes read.

Difference between Baseband and Broadband

In this article, we are going to learn about the differences between baseband and broadband. We are going to learn about importance of each in the respective fields. We are...

3 minutes read.

Difference between Longitude and Latitude

Difference between Longitude and Latitude Whenever we go to new place or destination and we don’t know the exact address, we simply put the name of the location on Google Map....

4 minutes read.

Difference between EIGRP and OSPF

Both EIGRP and OSPF are interior gateway routing protocols. The aim of both EIGRP and OSPF is to choose the best route to transfer information from source to destination with...

4 minutes read.

Difference between President and Prime Minister

The country's first citizen and head of state is the President. The Prime Minister, on the other hand, leads the country's government at the national level, together with the other...

4 minutes read.

Difference between Pure Substances and Impure Substances

Many people are confused between pure and impure substances. So, in this article, we will explain about both of them. What are Pure Substances? A pure material has a predictable chemical makeup....

3 minutes read.

Difference between Vision and Mission

Difference between Vision and Mission These words are really important for every organisation. Now a day, in fast-paced environment, every organisation must have a clear or pinned statement which is attractive. There...

6 minutes read.