I am wondering if there is a recommended way of centering text at a certain point in a line of text?
When trying to align monospace characters on multiple consecutive lines, alignment is fine with strings of equal length, with the alignment point in the middle. However, if the strings are of different length and/or the point where the string is to be aligned is off-center it is a bit more challenging.
I managed to do it by adding/subtracting space at the beginning of the lines using \hspace*
, but am curious if there is a better way of doing it.
Below is an example. First, there is the characters A-G, with "D" aligned in the center. If the "A" is removed from the first line, and "G" from the second, the text is no longer aligned at the "D". Finally, the last part shows the way I found of realigning at the "D".
\documentclass{article}
\begin{document}
\begin{center}
\texttt{ABCDEFG}\\
\texttt{GFEDCBA}
\par\vspace*{10pt}
\texttt{BCDEFG}\\
\texttt{GFEDCB}
\par\vspace*{10pt}
\hspace*{5pt}\texttt{BCDEFG}\\
\hspace*{-6pt}\texttt{GFEDCB}
\end{center}
\end{document}