LaTeX forum ⇒ Text FormattingVertical Centering in tabularx Topic is solved

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Timothée
Posts: 1
Joined: Fri Apr 19, 2019 10:44 am

Vertical Centering in tabularx  Topic is solved

Postby Timothée » Fri Apr 19, 2019 10:56 am

I have seen many topics on this subject, but it doesn't work with me.

I have a table, and I want to vertical align all the columns.

Consider this code:

  1. \begin{table}[h]
  2. \centering
  3. \sffamily \begin{tabularx}{\linewidth}{|X|c|c|c|c|c|c|X|}
  4. \hline
  5. \multicolumn{2}{|c|}{Topologie} & \#c & Motif & $v \in V$ obligatoire & $D$ & $\Delta$ & Complexité \\
  6. \hline
  7. $G$ & $H$ & \multirow{2}{*}{$2$} & \multirow{2}{*}{$=$} & \multirow{2}{*}{$\varnothing$} & \multirow{2}{*}{$\{1, qlc \}$} & \multirow{2}{*}{qlc} & \multirow{2}{*}{Inapprox} \\
  8. \cline{1-2}
  9. Graphe complet, intervalles propres, split-graph, étoile, $2$-coloration valide, graphe-bloc, arbre & qlc & & & & & & \\
  10. \hline
  11. \end{tabularx} \normalfont
  12. \caption{Synthèse des conditions étudiées.}
  13. \label{tab:Appr}
  14. \end{table}


As is, this produces:

TAB1.png
TAB1.png (17.68 KiB) Viewed 114 times


But I want something like this :

TAB2.png
TAB2.png (21.05 KiB) Viewed 114 times


So, how can I have a column verticaly align ?

rais
Posts: 197
Joined: Sun Nov 16, 2014 8:51 pm

Postby rais » Sun Apr 21, 2019 10:54 am

Well, you'll have to redefine the X column to be based on a m-column instead of a p-column, see \tabularxcolumn in tabularx' documentation.
Then you have to take into account, that the number of lines is increased by the number of line breaks introduced by the contents of these X columns. As such, 2 is not enough for your \multirow commands.
Or you rearrange the table a bit, no longer needing the \multirows alltogether:
  1. \documentclass[a4paper]{report}
  2. \usepackage[T1]{fontenc}
  3. \usepackage[french]{babel}
  4. \usepackage[left=2cm,right=4cm]{geometry}
  5. \usepackage{amssymb}
  6. \usepackage{tabularx}
  7. \renewcommand\tabularxcolumn[1]{m{#1}}
  8. \begin{document}
  9. \begin{table}[ht]
  10. \centering\sffamily
  11. \begin{tabularx}{\linewidth}{|@{}c@{}|c|c|c|c|c|X|}
  12. \hline
  13. Topologie & \#c & Motif & $v \in V$ obligatoire & $D$ & $\Delta$ & Complexité \\
  14. \hline
  15. {\begin{tabularx}{4cm}{X|c}
  16. $G$ & $H$\\
  17. \hline
  18. Graphe complet, intervalles propres, split-graph, étoile, $2$-coloration valide, graphe-bloc, arbre & qlc\\
  19. \end{tabularx}} &
  20. $2$ & $=$ &$\varnothing$ & $\{1, qlc \}$ & qlc & Inapprox\\
  21. \hline
  22. \end{tabularx}\normalfont
  23. \caption{Synthèse des conditions étudiées.}
  24. \label{tab:Appr}
  25. \end{table}
  26. \end{document}

Happy Easter;-)
Rainer


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 2 guests