# How can I set the width of lrbox in latex?

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

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}


Further options include using a minipage.

• +1 i wondered if it might be possible to do it with a list environment, which might allow page breaks...? Jun 7, 2020 at 10:06
• @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, 2020 at 17:41