Why do I get a line in the middle?
\documentclass{article}
\begin{document}
%%\parbox[alignment][height][inner-alignment]{width}{text}
The answer is:\parbox[c][][b]{2cm}{\hrulefill}.\par
\end{document}
A \parbox is certainly not the right tool for this job.
If you want a 2cm wide rule sitting at mid height of lowercase letters, you can do
\documentclass{article}
\newcommand{\middlerule}[2][0.4pt]{%
\raisebox{\dimexpr0.5ex-(#1)/2}{\rule{#2}{#1}}%
}
\begin{document}
The answer is:~\middlerule{2cm}
\end{document}
Or, with the \vrule primitive,
\documentclass{article}
\newcommand{\middlerule}[2][0.4pt]{%
\vrule
height \dimexpr0.5ex+(#1)/2\relax
depth \dimexpr(#1)/2-0.5ex\relax
width #2\relax
}
\begin{document}
The answer is:~\middlerule{2cm}
\end{document}
With either version, the input
The answer is:~\middlerule[1pt]{2cm}
would produce a 1pt thick rule.
Thanks to @leandriis,
\documentclass{article}
\begin{document}
The answer is:\parbox[b]{2cm}{\hrulefill}.\par
\end{document}
\rule would be the more natural command here. also the optional arguments [][b] do nothing (the final b option can only have any effect if you specify a vertical height with the second option).
– David Carlisle
Nov 05 '21 at 20:46
\parbox[b]instead of\parbox[c]should work. The first optional argument determines the vertical position of the parbox. You usedcwhich means vertically centered ans is exactly what you get. – leandriis Nov 05 '21 at 20:11The answer is: \rule{2cm}{0.4pt}. – Bernard Nov 05 '21 at 20:21