[Tex/LaTex] Line breaks inside commands

line-breaking

Is there a way to have line breaks inside commands that don't accept line breaks. For example,

\documentclass{article}

\begin{document}

    \mbox{line 1\\line 2}

\end{document}

Best Answer

Some examples and solutions:

\documentclass{article}
\usepackage{varwidth}
\usepackage{parskip}
\begin{document}

\texttt{line 1\\line 2}

\emph{line 1\\line 2}

But:

\mbox{line 1\\line 2}

\fbox{line 1\\line2}

Solutions:

\fbox{\parbox{5cm}{line 1\\line 2}} % or environment minipage

% varwidth is like minipage, but truncates the lines if possible:
\fbox{\begin{varwidth}{5cm}line 1\\line 2\end{varwidth}}

\fbox{\begin{tabular}{ll}line 1\\line 2\end{tabular}}

\end{document}

Result

Related Question