Graphics, Figures & TablesLeft Aligning Text in Longtable

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
parkerokabe
Posts: 7
Joined: Thu Apr 25, 2019 5:45 pm

Left Aligning Text in Longtable

Post by parkerokabe »

Hi! It took me hours how to figure out how to build this table and make it fit in my margins, but now my only issue is that I can't move the headers to the left. It's mostly just the second heading that has a big gap between "Particle" and "Size". I cut out some of the numbers to make it shorter. Any help would be greatly appreciated!

\documentclass[review]{elsarticle}

\usepackage{lineno,hyperref,upgreek,graphicx,chemformula,subfig,longtable,multirow}
\modulolinenumbers[5]
\usepackage{geometry}
\geometry{%
letterpaper, % a4paper
left= 2.54 cm,
right= 2.54 cm,
top= 2.54 cm,
bottom= 2.54 cm,
}

\journal{Journal of Nuclear Materials}

\begin{center}
\begin{longtable}[c]{ p{1cm} p{2.5cm} p{1.5cm} p{1.5cm} p{2cm} p{2cm}}
\caption{Summary of Chlorination Test Results.}\\

& & & & \multicolumn{2}{l}{Conversion (\%)}\\\cline{5-6}
Time (min) & Particle Size Range ($\upmu$m) & Set Point Temp (K) & vol\%Cl\textsubscript{2} & Mass-Based & CIE-Based\\
\hline\hline
\endfirsthead

\hline
& & & & \multicolumn{2}{l}{Conversion (\%)}\\\cline{5-6}
Time (min) & Particle Size Range (~$\upmu$m) & Set Point Temp (K) & vol\%Cl\textsubscript{2} & Mass-Based & CIE-Based\\
\hline\hline
\endhead

\hline
\endfoot

\hline
\endlastfoot

10 & \textless4,000 & 573 & 100 & 62.4 & 58.4\\
20 & \textless4,000 & 573 & 100 & 46.8 & 68.8\\
26 & \textless4,000 & 573 & 100 & 59.6 & 69.0\\
33 & \textless4,000 & 573 & 100 & 72.9 & 66.7\\
10 & Microns-4,000 & 523 & 100 & 66.3 & 85.0\\
30 & Microns-4,000 & 523 & 100 & 66.8 & 78.1\\
60 & Microns-4,000 & 523 & 100 & 65.9 & 85.1\\
90 & Microns-4,000 & 523 & 100 & 71.3 & 84.4\\
60 & 1,000-2,000 & 523 & 100 & 15.2 & 17.1\\
60 & 355-425 & 523 & 100 & 86.3 & 89.2\\
60 & 250-355 & 523 & 100 & 92.6 & 93.1\\
60 & 150-250 & 523 & 100 & 92.3 & 92.0\\
\end{longtable}
\end{center}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

user22741
Posts: 35
Joined: Fri Nov 09, 2018 12:03 pm

Left Aligning Text in Longtable

Post by user22741 »

The `ragged2e` package has the great `\RaggedRight` macro for such cases:

Code: Select all

\documentclass[review]{elsarticle}

\usepackage{lineno,hyperref,upgreek,graphicx,chemformula,subfig,longtable,multirow}
\modulolinenumbers[5]
\usepackage{geometry}
\geometry{%
letterpaper, % a4paper
left= 2.54 cm,
right= 2.54 cm,
top= 2.54 cm,
bottom= 2.54 cm,
showframe
}

\usepackage{ragged2e}
\usepackage{array}

\newcolumntype{R}[1]{>{\RaggedRight}p{#1}}

\journal{Journal of Nuclear Materials}



\begin{document}
\begin{longtable}[c]{ R{1cm} R{2.5cm} R{1.5cm} R{1.5cm} R{2cm} R{2cm}}
\caption{Summary of Chlorination Test Results.}\\

& & & & \multicolumn{2}{l}{Conversion (\%)}\\\cline{5-6}
Time (min) & Particle Size Range ($\upmu$m) & Set Point Temp~(K) & vol\%Cl\textsubscript{2} & Mass-Based & CIE-Based\\
\hline\hline
\endfirsthead

\hline
& & & & \multicolumn{2}{l}{Conversion (\%)}\\\cline{5-6}
Time (min) & Particle Size Range (~$\upmu$m) & Set Point Temp (K) & vol\%Cl\textsubscript{2} & Mass-Based & CIE-Based\\
\hline\hline
\endhead

\hline
\endfoot

\hline
\endlastfoot

10 & \textless4,000 & 573 & 100 & 62.4 & 58.4\\
20 & \textless4,000 & 573 & 100 & 46.8 & 68.8\\
26 & \textless4,000 & 573 & 100 & 59.6 & 69.0\\
33 & \textless4,000 & 573 & 100 & 72.9 & 66.7\\
10 & Microns-4,000 & 523 & 100 & 66.3 & 85.0\\
30 & Microns-4,000 & 523 & 100 & 66.8 & 78.1\\
60 & Microns-4,000 & 523 & 100 & 65.9 & 85.1\\
90 & Microns-4,000 & 523 & 100 & 71.3 & 84.4\\
60 & 1,000-2,000 & 523 & 100 & 15.2 & 17.1\\
60 & 355-425 & 523 & 100 & 86.3 & 89.2\\
60 & 250-355 & 523 & 100 & 92.6 & 93.1\\
60 & 150-250 & 523 & 100 & 92.3 & 92.0\\
\end{longtable}
\end{document}
Screen Shot 2019-04-26 at 21.08.24.png
Screen Shot 2019-04-26 at 21.08.24.png (64.99 KiB) Viewed 15063 times
Last edited by user22741 on Fri Apr 26, 2019 9:10 pm, edited 1 time in total.
parkerokabe
Posts: 7
Joined: Thu Apr 25, 2019 5:45 pm

Left Aligning Text in Longtable

Post by parkerokabe »

user22741 wrote:The `ragged2e` package has the great `\RaggedRight` macro for such cases:

Code: Select all

\documentclass[review]{elsarticle}

\usepackage{lineno,hyperref,upgreek,graphicx,chemformula,subfig,longtable,multirow}
\modulolinenumbers[5]
\usepackage{geometry}
\geometry{%
letterpaper, % a4paper
left= 2.54 cm,
right= 2.54 cm,
top= 2.54 cm,
bottom= 2.54 cm,
showframe
}

\usepackage{ragged2e}
\usepackage{array}

\newcolumntype{R}[1]{>{\RaggedRight}p{#1}}

\journal{Journal of Nuclear Materials}



\begin{document}
\begin{longtable}[c]{ R{1cm} R{2.5cm} R{1.5cm} R{1.5cm} R{2cm} R{2cm}}
\caption{Summary of Chlorination Test Results.}\\

& & & & \multicolumn{2}{l}{Conversion (\%)}\\\cline{5-6}
Time (min) & Particle Size Range ($\upmu$m) & Set Point Temp~(K) & vol\%Cl\textsubscript{2} & Mass-Based & CIE-Based\\
\hline\hline
\endfirsthead

\hline
& & & & \multicolumn{2}{l}{Conversion (\%)}\\\cline{5-6}
Time (min) & Particle Size Range (~$\upmu$m) & Set Point Temp (K) & vol\%Cl\textsubscript{2} & Mass-Based & CIE-Based\\
\hline\hline
\endhead

\hline
\endfoot

\hline
\endlastfoot

10 & \textless4,000 & 573 & 100 & 62.4 & 58.4\\
20 & \textless4,000 & 573 & 100 & 46.8 & 68.8\\
26 & \textless4,000 & 573 & 100 & 59.6 & 69.0\\
33 & \textless4,000 & 573 & 100 & 72.9 & 66.7\\
10 & Microns-4,000 & 523 & 100 & 66.3 & 85.0\\
30 & Microns-4,000 & 523 & 100 & 66.8 & 78.1\\
60 & Microns-4,000 & 523 & 100 & 65.9 & 85.1\\
90 & Microns-4,000 & 523 & 100 & 71.3 & 84.4\\
60 & 1,000-2,000 & 523 & 100 & 15.2 & 17.1\\
60 & 355-425 & 523 & 100 & 86.3 & 89.2\\
60 & 250-355 & 523 & 100 & 92.6 & 93.1\\
60 & 150-250 & 523 & 100 & 92.3 & 92.0\\
\end{longtable}
\end{document}

I added the lines
\usepackage{ragged2e}
\usepackage{array}

\newcolumntype{R}[1]{>{\RaggedRight}p{#1}}

but nothing changed. Am I missing something?
user22741
Posts: 35
Joined: Fri Nov 09, 2018 12:03 pm

Left Aligning Text in Longtable

Post by user22741 »

The table has also to use the new column type.
parkerokabe
Posts: 7
Joined: Thu Apr 25, 2019 5:45 pm

Left Aligning Text in Longtable

Post by parkerokabe »

user22741 wrote:The table has also to use the new column type.
It worked! Thank you so much!
Post Reply