Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • 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}
@btjanaka
Copy link

Really helpful. Thanks!

@CharizardAcademy
Copy link

thank you, it works like a charm :)

@AleMuzzi
Copy link

You saved me a lot of time, thanks!

@austinkocher
Copy link

Fantastic! This is brilliant.

@skang67
Copy link

skang67 commented Sep 30, 2022

Great help. Thanks!

@lifangda01
Copy link

Very helpful.

@MartinRisoy
Copy link

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

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