2

Reading this other thread, I found how to right align a column in longtable. However if I want to right align two columns that are next to each other:

\newcolumntype{R}{>{\raggedleft\arraybackslash}p{6cm}|}                                                                                                                                                              
%                                                                                                                                                                                                                    
\begin{document}                                                                                                                                                                                                     
\begin{longtable}{|p{9.32cm}|R{5.97cm}|R{3.14cm}|p{4.57cm}|}

Ends up with columns alignments mixed up, but not the way I want (1st and last left ligned, the other two right aligned)

3

You can define another column type for the other alignment. Notice that I used an argument in the definitions, so you can use the desired widths (I changed the widths in my example so the table will fit in the page):

\documentclass{article}
\usepackage{array}
\usepackage{longtable}

\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}                                                                                                                                                              
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}                                                                                                                                                              

\begin{document}                                                                                                                                                                                                     

\begin{longtable}{|L{3.32cm}|R{3.97cm}|R{3.14cm}|L{3.57cm}|}
some text goes here to illustrate the alignment &
some text goes here to illustrate the alignment &
some text goes here to illustrate the alignment &
some text goes here to illustrate the alignment
\end{longtable}

\end{document}

enter image description here

  • Thanks!! Any chance to have headers centered, while rows left and right aligned? – maraujop Jun 17 '13 at 14:41
  • 1
    @maraujop You're welcome! Regarding your question, you can use \multicolumn to override the column type specification for the headers: \multicolumn{1}{|c|}{header1} & \multicolumn{1}{c|}{header2} & \multicolumn{1}{c|}{header3} & \multicolumn{1}{c|}{header4} \\ . – Gonzalo Medina Jun 17 '13 at 14:58
  • Definitely you know Latex, thanks!! I was going nuts with this. – maraujop Jun 17 '13 at 15:14
  • I've just realized that doing this breaks my seqsplit. Sometimes my column names are very long words. Thus columns extend to wrap those words and my column widths get all messed up, any hints? thanks – maraujop Jun 17 '13 at 15:59
  • @maraujop No idea without some example of your actual code. Please, feel free to open a follow-up question. Make sure to include there a minimal working example showing the problem mentioned. – Gonzalo Medina Jun 17 '13 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.