Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LanternD/1edd0fcc64f287d841b6da3ec38c69a2 to your computer and use it in GitHub Desktop.
Save LanternD/1edd0fcc64f287d841b6da3ec38c69a2 to your computer and use it in GitHub Desktop.
LaTeX - Fixed table column width while aligning text left/center/right
\documentclass{article}
\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\begin{document}
\begin{tabular}{| c | L{3cm} | C{3cm} | R{3cm} |}
foo &
A cell with text that wraps around, is raggedright and allows \newline
manual line breaks &
A cell with text that wraps around, is centered and allows \newline
manual line breaks &
A cell with text that wraps around, is raggedleft and allows \newline
manual line breaks \\
\end{tabular}
\end{document}
@lifangda01
Copy link

Very helpful.

@MartinRisoy
Copy link

Thank you for that, helped my table from looking like a piece of garbage.

@rybd111
Copy link

rybd111 commented Jun 6, 2024

Thank you. Very useful!

@gblmrn
Copy link

gblmrn commented Oct 5, 2024

Good job, Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment