1

I need to set the width of lrbox to a particular size. I am trying with the following code:

\begin{lrbox}[width=.5\linewidth]
  ...
\end{lrbox}

However, it is throwing error. Any idea how can I set the width of lrbox? Thanks

2

Welcome! You can use e.g. \makebox or \parbox.

\documentclass{article}
\newsavebox\mybox
\begin{document}
\begin{lrbox}\mybox
\makebox[.5\linewidth][l]{pft}
\end{lrbox}

\usebox\mybox
\medskip

The width of the \texttt{lrbox} is \texttt{\the\wd\mybox}, and the line width is
\texttt{\the\linewidth}.
\bigskip

\begin{lrbox}\mybox
\parbox{.5\linewidth}{pft pft pft pft pft pft pft pft pft pft pft pft pft pft pft pft pft pft pft pft pft pft}
\end{lrbox}

\usebox\mybox
\medskip

The width of the \texttt{lrbox} is \texttt{\the\wd\mybox}, and the line width is
\texttt{\the\linewidth}.

\end{document}

enter image description here

Further options include using a minipage.

2
  • +1 i wondered if it might be possible to do it with a list environment, which might allow page breaks...? – cmhughes Jun 7 '20 at 10:06
  • 1
    @cmhughes For that one can use a breakable tcolorbox. But of course this will no longer be an lrbox/savebox, which to the best of my knowledge do not support page breaks. – user194703 Jun 7 '20 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.