1

I am trying to make simple tables that span the width of my body text with the \newcolumntype command in LaTeX.

In the left column, I would like the text to be right-aligned (within the column). However, I'd like the left-hand side of this column to align with my left margin.

In the right column, I'd like the text to be left-aligned, and continue until it reaches the right margin.

I'd like there to be a small bit of padding between the two columns.

My current code is as follows:

\newcolumntype{L}{>{\raggedleft}p{0.2\textwidth}}
\newcolumntype{R}{p{0.7\textwidth}}

Tables are:

\begin{tabular}{L!{}R}
...
\end{tabular}

The problem I am having is that the left-hand column will not align with my left margin in my document. Instead, it severely indents. I cannot figure out how to fix it. Any advice is greatly appreciated!

8
  • 2
    Welcome to TeX SX! Using as the table preamble \begin{tabular}{@{}LR@{}} should do what you want.
    – Bernard
    Jun 2, 2021 at 23:35
  • Thanks @Bernard! I'm still seeing an indent on my tabular environment when I use this preamble. I'm using the longtable environment, if relevant! Is there some way to remove this indent in longtable?
    – Anna Jones
    Jun 2, 2021 at 23:37
  • Maybe you have a blank line before your long table? Or I would suggest using the xltabular environment (homonymous package), which nrings the functionalities of longtable to tabularx. The table should begin with \begin{xltabular}{@{}>{\hsize=0.5\hsize}X>{\hsize=1.5\hsize\arraybackslash}X@{}}
    – Bernard
    Jun 2, 2021 at 23:50
  • Thanks for your suggestion, @Bernard! When I use xltabular some of the command `begin{xltabular}...' that you provided prints to the page instead of "working" for me! So I'm not sure what's up, unfortunately!
    – Anna Jones
    Jun 2, 2021 at 23:54
  • 1
    I've been using a longtable environment so that the content of my tables automatically continues on the next page, if they end up being long (which I expect they will, for this paper). However, if you have an alternative suggestion that might be better, I would appreciate any advice!
    – Anna Jones
    Jun 3, 2021 at 0:03

1 Answer 1

1

I suggest you employ a tabular* rather than a tabular environment and set the overall width of the tabular* environment to \textwidth.

Since you wrote, "In the right column, I'd like the text to be left-aligned", I think the column definition should be

\newcolumntype{R}{>{\raggedright}p{0.7\textwidth}}

rather than just

\newcolumntype{R}{p{0.7\textwidth}}

And do insert the instruction \noindent right before \begin{tabular*}.

The framelines in the following screenshot are drawn because the showframe package is loaded in the underlying brief test document.

enter image description here

\documentclass{article}
\usepackage{array,showframe,lipsum}
\newcolumntype{L}{>{\raggedleft} p{0.225\textwidth}}
\newcolumntype{R}{>{\raggedright}p{0.725\textwidth}}
\begin{document}

\noindent% <-- very important
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} LR @{}}
\lipsum[1][2-4] & \lipsum[2]  \\
\end{tabular*}

\end{document}

Addendum: Here's how you might achieve the same outcome while using a longtable environment instead of a tabular* environment. (I'm not posting a second screenshot, as it would be identical to the one shown above.)

\setlength\LTleft{0pt}
\setlength\LTright{0pt}
\begin{longtable}{@{\extracolsep{\fill}} LR @{}}
\lipsum[1][2-4] & \lipsum[2]  \\
\end{longtable}
4
  • 1
    Thanks for this suggestion! I will play around with it and see how it works for me.
    – Anna Jones
    Jun 3, 2021 at 0:04
  • @AnnaJones - I've provided an addendum to show how the same result may be achieved with a longtable environment.
    – Mico
    Jun 3, 2021 at 5:29
  • Hello @Mico! Your longtable strategy worked for me, in that the left column has now stopped indenting! Thanks very much. However, now when I have more than two rows in a table, the table does not seem to understand how to "end" one row and go to the next. E.g., if I type textA & textB \\ textC & text D, sometimes textC ends up in column 1 and/or in other odd places in the table where it does not belong, and I get the "Extra alignment tab has been changed to \cr" warning. If you have any advice, I would appreciate it greatly!
    – Anna Jones
    Jun 3, 2021 at 21:21
  • @AnnaJones - I'm afraid you haven't provided enough information to allow a proper diagnosis of the situation. May I ask you to post a new query, ideally in the form of a compilable test document that starts with \documentclass, ends with \end{document}, and generates the problem behavior you wish to fix? Thanks.
    – Mico
    Jun 3, 2021 at 21:39

You must log in to answer this question.

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