For my study I need to put some information in a tabular
. I'm using tabularx
and to determine to width of my columns I use \parbox
. That all works very good, but the text on both columns doesn't start at the same level. I'd like to have the text on the left column at the same hight as the text on the right column, how can I do that ?
\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage{french}
\setotherlanguages{english,german,latin,italian,spanish,russian,greek}
\usepackage{tabularx}
\begin{document}
\begin{center}
\begin{tabularx}{\linewidth}{|@{}>{\bfseries}l|@{\hspace{.5em}}X@{}|}
\hline \parbox{3cm}{text} & text \\
\hline \parbox{3cm}{text} & text \\
...
\end{tabularx}
\end{center}
\end{document}
Best Answer
For the first column, don't specify
l
as the column type and then use a\parbox
(of width3cm
) to typeset its material. Instead, usep{3cm}
directly as the column type specifier.In view of the rather narrow measure that's set for the first column, I would use ragged-right rather than full (ie., left and right) justification.
Addendum to address @u2berggeist's follow-up question:
Let me begin with an excerpt from the user guide of the
array
package:This is admittedly rather terse. Let me attempt to provide a somewhat wordier explanation of the purpose of
\arraybackslash
.When using
\newcolumntype
to define a new column type, the meaning of\\
gets changed (for reasons I admit to never having fully grasped). The upshot, though, is that\\
is no longer the macro that creates a line break; one has to use\tabularnewline
instead. The instruction\arraybackslash
simply restores the widely-expected behavior of\\
. (I don't think I've every met anyone who prefers to type\tabularnewline
over\\
...)It is the case, in the code shown above, that there are no forced line breaks in the
P
column (the first column). Hence, it was not strictly necessary to employ\arraybackslash
in the\newcolumntype
definition ofP
. So why did I use\arraybackslash
anyway? I did it for two reasons.First, it never hurts to do so -- unless one has a hankering for typing
\tabularnewline
...Second, if the
P
column were used in the final column instead of in the first column, the failure to have employed\arraybackslash
in the\newcolumntype
instruction would generate some rather cryptic error messages which would certainly baffle everybody not named David Carlisle. The postings on this site often turn up in Google searches, even years after they were made. This answer, say, might turn up in a search for "latex table raggedright column". A casual reader of this answer might gladly noteand might even take note of the fact that it's necessary to load the
ragged2e
package (as it defines\RaggedRight
). What a casual reader may well miss -- and, in fact, should be excused for having missed! -- is that in thetabularx
environment at hand, theP
column type doesn't get used in the final column. Had I postedthe answer would have still "worked" for the given
tabularx
environment; however, it would have needlessly risked creating huge amounts of frustration among future users who performed a web search with the terms "latex table raggedright column" and were interested in using theP
column type for the final, i.e., right-hand-most, column of theirtabular
-like environment.Did I succeed in answering your question?