Basically, I want to produce the following table in LaTeX
(Notice the "comma alignment" of the second cell) :
----------------------------------------
| Header1 | Header2 |
----------------------------------------
| 1 | "value 1" , "value 2" |
| 2 | "one" , "two" |
| 3 | "abcdefheasal" , "ok" |
----------------------------------------
The way I would produce the table above in LaTeX
is as follows:
\begin{tabular}{|c|l|}
\hline
Header1 & Header2 \\
\hline
1 & ``value 1'' , ``value 2'' \\
2 & ``one'' , ``two'' \\
3 & ``abcdefheasal'' , ``ok'' \\
\hline
\end{tabular}
But obviously, that code produces the following (obviously without the "comma alignment") :
-----------------------------------
| Header1 | Header2 |
-----------------------------------
| 1 | "value 1" , "value 2" |
| 2 | "one" , "two" |
| 3 | "abcdefheasal" , "ok" |
-----------------------------------
What is the best way to turn the latter table into the one I want? i.e. the former
You can also use r to align the text to the right and l for left alignment. This will insert a horizontal line on top of the table and at the bottom too. There is no restriction on the number of times you can use \hline . Each & is a cell separator and the double-backslash \\ sets the end of this row.
To place an item at the top or bottom of its cell, insert the "VALIGN=" attribute within the code for that cell. To vertically align an entire row (e.g., placing all data in that row at the tops of the cells), insert the "VALIGN=" attribute within the code for that row.
Full Justify Text By default, LaTeX fully justifies text in LaTeX documents. However, you can explicitly specify this if you are using a different alignment method. To do this, use the \justify command.
As a modification to Martin B's answer, consider using the @
sign to make a column separator:
\begin{tabular}{|c|l@{ , }l|}
\hline
Header1 & \multicolumn{2}{l|}{Header2} \\
\hline
1 & ``value 1'' & ``value 2'' \\
2 & ``one'' & ``two'' \\
3 & ``abcdefheasal'' & ``ok'' \\
\hline
\end{tabular}
Also note that an extra pipe is needed in the multicolumn
to draw the vertical line on the first row.
I would suggest using a three-column table, then merging the header of the second and third column, as follows:
\begin{tabular}{|c|ll|}
\hline
Header1 & \multicolumn{2}{l}{Header2} \\
\hline
1 & ``value 1'' & , ``value 2'' \\
2 & ``one'' & , ``two'' \\
3 & ``abcdefheasal'' & , ``ok'' \\
\hline
\end{tabular}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With