[Tex/LaTex] How to create two boxes in the same line

boxesverbatim

How can I create two boxes in the same line with words in between(as the picture below which I made using MS-Word)? I tried \makebox, \fbox or \minipage and none of them seem to be working, maybe because I am using verbatim environment at the same time. I am trying to make a section illustrating how to type Chinese in LaTeX.

I have tried

\fbox{
\begin{minipage}{5cm}
\begin{verbatim}
\documentclass{article}
\usepackage[UTF8]{ctex}
\end{verbatim}  
\end{minipage}
}

or any other possible combination of this three command but the typeset engine always give me errors says there is one extra { at the end of the code, even though it should be the right bracket of \fbox.
The effect I want

Best Answer

For an easy-to-use application, just set these in a tabular:

enter image description here

\documentclass{article}

\begin{document}

Either
\begin{tabular}{ | @{\,} l @{\,} | }
  \hline
  \verb|\documentclass{article}| \\
  \verb|\usepackage[UTF8]{ctex}| \\
  \hline
\end{tabular}
or
\begin{tabular}{ | @{\,} l @{\,} | }
  \hline
  \verb|\documentclass[UTF8]{ctexart}| \\
  \verb|\begin{document}| \\
  \verb|\end{document}| \\
  \hline
\end{tabular}.

\end{document}

Another option using fancyvrb to save the verbatim content and use it inside \fbox:

enter image description here

\documentclass{article}

\usepackage{fancyvrb}

\begin{document}

\begin{SaveVerbatim}{optA}
\documentclass{article}
\usepackage[UTF8]{ctex}
\end{SaveVerbatim}
\begin{SaveVerbatim}{optB}
\documentclass[UTF8]{ctexart}
\begin{document}
\end{document}
\end{SaveVerbatim}

Either \fbox{\strut\BUseVerbatim{optA}} or \fbox{\strut\BUseVerbatim{optB}}.

\end{document}

\struts ensure a consistent baseline with respect to the two verbatims.

Related Question