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!
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- Stefan Kottwitz
- Site Admin
- Posts: 10359
- 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: 10359
- 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: 10359
- 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