[Tex/LaTex] Tabularx \parbox horizontal alignment of columns

tabularx

enter image description here

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 width 3cm) to typeset its material. Instead, use p{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.

enter image description here

\documentclass{article}     
\usepackage{polyglossia}    
\setmainlanguage{french}    
\setotherlanguages{english,german,latin,italian,spanish,russian,greek}     
\usepackage{tabularx} 
\usepackage{ragged2e} % for "\RaggedRight" macro  
\newcolumntype{P}[1]{>{\RaggedRight\arraybackslash}p{#1}}
\usepackage{lipsum} % for filler text

\begin{document}    
\noindent  
\begin{tabularx}{\linewidth}{ @{}
    >{\bfseries}P{3cm} | @{\hspace{.5em}}
    X @{}}
\hline  
Once upon a time, there was an enchanted castle \dots & 
\lipsum*[1] \\     
\hline 
text  & text  \\           
\end{tabularx}       
\end{document} 

Addendum to address @u2berggeist's follow-up question:

can you explain the necessity of the \arraybackslash command in the column type definition

Let me begin with an excerpt from the user guide of the array package:

\arraybackslash: Restore \\ for use in array and tabular environment (after \raggedright etc.).

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 of P. 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 note

    \newcolumntype{P}[1]{>{\RaggedRight\arraybackslash}p{#1}}
    

    and 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 the tabularx environment at hand, the P column type doesn't get used in the final column. Had I posted

    \newcolumntype{P}[1]{>{\RaggedRight}p{#1}}
    

    the 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 the P column type for the final, i.e., right-hand-most, column of their tabular-like environment.

Did I succeed in answering your question?