1

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}

enter image description here

  • 1
    \parbox[b] instead of \parbox[c] should work. The first optional argument determines the vertical position of the parbox. You used c which means vertically centered ans is exactly what you get. – leandriis Nov 05 '21 at 20:11
  • 1
    It is as simple to use The answer is: \rule{2cm}{0.4pt}. – Bernard Nov 05 '21 at 20:21

2 Answers2

2

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}

enter image description here

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.

enter image description here

egreg
  • 1,121,712
0

Thanks to @leandriis,

\documentclass{article}

\begin{document} The answer is:\parbox[b]{2cm}{\hrulefill}.\par \end{document}

  • 4
    a Bernard commented, \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