# How to consistently horizontally align text across lines with a consistent horizontal gap in each line?

I have something like this:

\documentclass{article}

\begin{document}

\begin{tabular}{p{\linewidth}}
\textit{SOME LABEL}\hspace{1em}Lorem ipsum dolor sit amet, consectetur adipiscing elit $x_1 \ldots x_n$. \\
\textit{SOME LABEL}\hspace{1em}Nullam nec mi et neque pharetra sollicitudin.
\end{tabular}

\end{document}


It ultimately looks like:

The first line breaks early and is justified because I guess it didn't want a line break in the middle of math mode. However, this causes "SOME LABEL" and "Lorem" to be misaligned with the row below.

How can I disable justification of "SOME LABEL" so that its horizontal edges always align across lines? Furthermore, how can I make the gap between it and the subsequent sentence consistent? I'd still like for the rest of the paragraph to be justified as usual.

You will get consistent spacing if you use \raggedright (either manually, with every cell in your table, or through an automated >{\raggedright} fashion thanks to array). But if you wish to keep the spacing for SOME LABEL fixed, set it in a box (either \mbox or \makebox). However, I almost feel you need to set a list (using description, for example).

\documentclass{article}

\usepackage{array,enumitem}

\begin{document}

\noindent
\begin{tabular}{@{} p{\linewidth} @{}}
\textit{SOME LABEL}\quad Lorem ipsum dolor sit amet, consectetur adipiscing elit $x_1 \ldots x_n$. \\
\textit{SOME LABEL}\quad Nullam nec mi et neque pharetra sollicitudin.
\end{tabular}

\medskip

\noindent
\begin{tabular}{@{} p{\linewidth} @{}}
\mbox{\textit{SOME LABEL}}\quad Lorem ipsum dolor sit amet, consectetur adipiscing elit $x_1 \ldots x_n$. \\
\mbox{\textit{SOME LABEL}}\quad Nullam nec mi et neque pharetra sollicitudin.
\end{tabular}

\medskip

\noindent
\begin{tabular}{@{} p{\linewidth} @{}}
\raggedright
\textit{SOME LABEL}\quad Lorem ipsum dolor sit amet, consectetur adipiscing elit $x_1 \ldots x_n$. \\
\raggedright
\textit{SOME LABEL}\quad Nullam nec mi et neque pharetra sollicitudin.
\end{tabular}

\medskip

\noindent
\begin{tabular}{@{} >{\raggedright}p{\linewidth} @{}}
\textit{SOME LABEL}\quad Lorem ipsum dolor sit amet, consectetur adipiscing elit $x_1 \ldots x_n$. \\
\textit{SOME LABEL}\quad Nullam nec mi et neque pharetra sollicitudin.
\end{tabular}

\medskip

\begin{description}[font=\normalfont\itshape]
\item[SOME LABEL]
Lorem ipsum dolor sit amet, consectetur adipiscing elit $x_1 \ldots x_n$.
Lorem ipsum dolor sit amet, consectetur adipiscing elit $x_1 \ldots x_n$.

\item[SOME LABEL]
Nullam nec mi et neque pharetra sollicitudin.
Nullam nec mi et neque pharetra sollicitudin.
\end{description}

\end{document}

• In practice, the table needs another column to the left, so I don't think a list would work. It'd be a nice solution otherwise. I can't get \raggedright to work with 2 columns: \begin{tabular}{p{0.5\linewidth} p{0.5\linewidth}}a & \raggedright b \\ c & \raggedright d\end{tabular} yields "Extra alignment tab has been changed to \cr." Apologies for not mentioning the 2nd column; I figured it wouldn't change the solution since misalignment occurs even outside a table. Feb 11, 2022 at 6:47
• @bgfvdu3w: Try with \raggedright\arraybackslash. And note that your table width will exceed \linewidth, even if you think that two 0.5\linewidth columns will fit; there are \tabcolseps around every column.
– Werner
Feb 11, 2022 at 7:06
• That worked! Good call on the width; I excluded the @{} in an attempt to make the inline code more readable. Why did you mention \mbox? "SOME LABEL" seems to have fixed spacing without it. Feb 11, 2022 at 7:19
• @bgfvdu3w: ...when you use \raggedright. Under normal justification \mbox will ensure the "original spacing" is preserved.
– Werner
Feb 11, 2022 at 12:06