I learnt that \parbox
has five arguments, that is: \parbox[<align>][<height>][<inner-align>]{<width>}{<text>}
. So I constrcut my own \myparbox in which I add \sloppy\setlength\parfillskip{0pt}
before #5. But it fails. What's the reason and how to re-define \myparbox?
MWE:
\documentclass{article}
\usepackage{xparse}
\NewDocumentCommand{\myparbox}{ooomm}{%
\parbox[#1][#2][#3]{#4}{\sloppy\setlength\parfillskip{0pt}#5}
}
\begin{document}
AAA\fbox{\parbox[][][]{4em}{aa bb cc dd ee ff}}AAA\\% parbox typesets nothing. why?
BBB\fbox{\myparbox{4em}{aa bb cc dd ee ff}}BBB% This fails to compile
\end{document}
EDIT:
\documentclass{article}
\usepackage{xparse}
\let\oldparbox\parbox
\RenewDocumentCommand{\parbox}{sO{c}oO{t}mm}{%
\IfBooleanTF{#1}
{%
\IfNoValueTF{#3}
{\oldparbox[#2]{#5}{\sloppy\setlength\parfillskip{0pt}#6}}
{\oldparbox[#2][#3][#4]{#5}{\sloppy\setlength\parfillskip{0pt}#6}}
}
{%
\IfNoValueTF{#3}
{\oldparbox[#2]{#5}{#6}}
{\oldparbox[#2][#3][#4]{#5}{#6}}
}
}
\begin{document}\the\fboxsep
AAA\fbox{\parbox[t]{8em}{aa bb cc dd ee ff gg hh ii}}AAA\\% parbox typesets nothing why?.
BBB\fbox{\parbox*{6em}{aa bb cc dd ee ff}}BBB% This fails to compile
\end{document}
[]
is not always the same as not giving an optional argument at all. Compare\parbox[][]{4em}{aa bb cc dd ee ff}
and\parbox[]{4em}{aa bb cc dd ee ff}
. In thexparse
example things get worse becauseo
's#1
becomes the special value-noValue-
when no optional argument is given. Naturally\parbox
can't deal with that.\parbox
in three different ways. Then you do not need to know about the kernel defaults. Use say\IfNoValueTF{#1}{true}{false}
and nest several of these.