How to use \fbox in LaTeX?

The \fbox command in LaTeX generates a box enclosing its specified argument. This can be useful for framing text, equations, or figures. Here’s a simple guide on how to use the \fbox command.

Basic Usage

The most basic form of the \fbox command is:

\fbox{Your content here}

Replace “Your content here” with the text, equation, or figure you want to frame.

Example 1: Text in a Box

\documentclass{article}

\begin{document}

We have added a \fbox{This is a framed text} in this example.

\end{document}

Output

This will put a black box around the text “This is a framed text.”

Example 2: Inline Equation in a Box

\documentclass{article}

\begin{document}

Albert Einstein's famous equation is expressed as: \fbox{$E=mc^2$}.

\end{document}

Output

This will put a black box around the equation “E=mc2.”

Example 3: Image in a Box

\documentclass{article}
\usepackage{graphicx}

\begin{document}

\begin{figure}
  \centering
\fbox{\includegraphics[width=0.8\textwidth]{green.jpg}}
  \caption{Framed Image}
  \label{Green}
\end{figure}

In Figure \ref{Green}, we can see a framed image.

\end{document}

Output

Customization

You can customize the appearance of the frame by adjusting the \fboxsep and \fboxrule parameters. You need to add the following lines in the preamble.

\setlength{\fboxsep}{10pt} % Adjust the separation
\setlength{\fboxrule}{2pt} % Adjust the frame line width

\fboxsep: This parameter determines the separation between the content (text, equation, figure, etc.) and the frame created by \fbox. By setting \fboxsep to 10pt, you are specifying a separation of 10 points. This will print the contents at a distance of 10 points from all the box lines. You can change the value according to your requirements.

\fboxrule: This parameter sets the width of the frame line created by \fbox. By setting \fboxrule to 2pt, you are specifying a frame line width of 2 points. This adjusts the thickness of the frame surrounding the content. You can change the value according to your requirements.

Let us take an example:

\documentclass{article}
\setlength{\fboxsep}{6pt}
\setlength{\fboxrule}{2pt}

\begin{document}

We have added a \fbox{This is a framed text} in this example.

\end{document}

Output

1 thought on “How to use \fbox in LaTeX?”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.