General ⇒ alignment in tabular
alignment in tabular
I need a table of the following format:
X | text in two lines | Y | paragraph-like text
The problem with using {c|p{x}|c|p{x}}:
If I break the line in the second column (to create the needed second line), the text of the first line spans over the whole width of the column, which looks extremely ugly.
The problem with using \multirow for the last column:
The text of the last column often (but not always) spans over more than two lines.
Any suggestions for an elegant solution? Is it possible to align paragraph-like text in tables to the left? That would be the easiest way to go, I guess.
Thanks a lot!
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
- Stefan Kottwitz
- Site Admin
- Posts: 10335
- Joined: Mon Mar 10, 2008 9:44 pm
alignment in tabular
you could use \raggedright inside cells or even in the column definition if you use the array package, for example
Code: Select all
>{\raggedright\arraybackslash}p{x}
Re: alignment in tabular
- Stefan Kottwitz
- Site Admin
- Posts: 10335
- Joined: Mon Mar 10, 2008 9:44 pm
alignment in tabular
It should work together with array, try it withradsim wrote:I didn't find out how to make the specification in the column definition (what you suggested gives me an error)
Code: Select all
\usepackage{array}
alignment in tabular
Code: Select all
\documentclass{article}
\usepackage{array}
\begin{document}
\begin{tabular}{|c|>{\raggedright}p{3cm}|c|>{\raggedright}p{3cm}|}
\hline
A & First line and now \\ the second line & B
& Fist line and also \\ a second line \tabularnewline \hline
C & Text, text, text, text & D
& Text, text, text, text, text \tabularnewline \hline
\end{tabular}
\end{document}
- Stefan Kottwitz
- Site Admin
- Posts: 10335
- Joined: Mon Mar 10, 2008 9:44 pm
alignment in tabular
\arraybackslash will work as expected if \\ is used to end rows and \newline to end lines inside cells, as you can see with this modification:
Code: Select all
\documentclass{article}
\usepackage{array}
\begin{document}
\begin{tabular}{|c|>{\raggedright}p{3cm}|c|>{\raggedright\arraybackslash}p{3cm}|}
\hline
A & First line and now \newline the second line & B
& Fist line and also \newline a second line \\ \hline
C & Text, text, text, text & D
& Text, text, text, text, text \\ \hline
\end{tabular}
\end{document}
Stefan