1

I want to have a list of texts in a document, and I use the "longtable" package to make the list. The codes as as following.

\documentclass{article}
\usepackage{longtable}
\begin{document}
    \begin{longtable}[h]{|p{0.2\textwidth}|p{0.60\textwidth}|p{0.2\textwidth}|}
        \multicolumn{2}{l}{\textbf{texts}}\\
        text 1-1                            &text 1-2                     &text 1-3    \\
        text 2-1                            &text 2-2                     &text 2-3    \\
        text 3-1                            &text 3-2                     &text 3-3    \\
        text 4-1                            &text 4-2                     &text 4-3    \\
        text 5-1                            &text 5-2                     &text 5-3    \\
        text 6-1                            &text 6-2                     &text 6-3    \\
    \end{longtable}
\end{document}

The document is as following.

enter image description here

The texts are left aligned by default.

The question is, I want to set the first and second column as "left align" and the thrid column as "right align". While, it seems that I can not use {llr} and {|p{0.2\textwidth}|p{0.60\textwidth}|p{0.2\textwidth}|} at the same time.

Then, how could I set the the width of column and set the align?

wxwuse
  • 139
  • 3
    Try >{\raggedleft\arraybackslash} before the p{…} you want right aligned. See the manual of package array for more information. – cabohah Jul 12 '23 at 14:27
  • 3
    If you don't need automatic line breaks, you could use w{r}{0.2\textwidth} from the array package – samcarter_is_at_topanswers.xyz Jul 12 '23 at 14:30
  • 1
    related: https://tex.stackexchange.com/q/12703/277964 – cabohah Jul 12 '23 at 14:33
  • 2
    Off-topic: Your longtable is to wide, because 0.2\textwidth + 0.6\textwidth + 0.2\textwidth + 6\tabcolsep (two for each column) are already > \textwidth. You either should reduce the width of at least one column or maybe you want to use package xltabular or tabularray to avoid such issues. And please note, that environment longtable does not support option [h] only [c], [l] and [r] are supported. See Table 7 in the longtable manual for more information. – cabohah Jul 12 '23 at 16:04
  • In the above example, all of the texts are one line, in which case you should be using l, c, and r columns. You can preset the width using \makebox or the makecell package. – John Kormylo Jul 13 '23 at 03:21

0 Answers0