1

So I am trying to center my text across the center of the \makebox.

Code:

\documentclass[12pt]{article}

\begin{document}
    \makebox[2in]{\hrulefill\rlap{John Doe}\hrulefill}
\end{document}

enter image description here

Right now, the text is starting to appear at the center of the \makebox instead of being centered at \makebox's center. Is there a way to fix it?

0

1 Answer 1

2

\rlap produces a box of width 0 the left "anchor" of which is aligned with the current position. You need something that aligns the center of the current position. You can use either \makebox[0pt]{...} (or \makebox[0pt][c]{...}), or \clap{...} from the mathtools package for that.

\documentclass[12pt]{article}
\usepackage{mathtools}
\begin{document}
\noindent\makebox[2in]{\hrulefill\rlap{John Doe}\hrulefill}

\noindent\makebox[2in]{\hrulefill\makebox[0pt]{John Doe}\hrulefill}

\noindent\makebox[2in]{\hrulefill\clap{John Doe}\hrulefill}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .