LaTeX forum ⇒ Graphics, Figures & TablesDifferent vertical Alignment in Table Columns Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
richi-rich
Posts: 4
Joined: Tue Jul 30, 2013 10:13 am

Different vertical Alignment in Table Columns

Postby richi-rich » Tue Jul 30, 2013 10:39 am

Hy,

I still haven't found a solution for the following problem:

I want to create a table in which specified columns should be vertically centered, but not all. In the first column the text should be aligned at the top.

Within the tabularx environment the m{} column aligns the text along with the top line. Redefining the X column with \renewcommand{\tabularxcolumn}[1]{m{#1}} helps to center the columns, but then the p{} column is ignored (or does something I don't understand :) )

Here is the example:

  1. \documentclass[a4paper,14pt,BCOR10mm,oneside]{scrartcl}
  2. \usepackage[ngerman]{babel}
  3. \usepackage[utf8]{inputenc}
  4. \usepackage[babel,german=quotes]{csquotes}
  5. \usepackage[T1]{fontenc}
  6. \usepackage{tabularx}
  7. \usepackage[absolute,overlay]{textpos}
  8. \usepackage{wallpaper}
  9. \usepackage{tabu}
  10. \areaset{17cm}{26cm}
  11. \setlength{\topmargin}{-1.5cm}
  12. \setlength{\marginparwidth}{0.5cm}
  13.  
  14. \renewcommand{\familydefault}{\sfdefault}
  15. \usepackage{helvet}
  16.  
  17. \renewcommand{\tabularxcolumn}[1]{m{#1}}
  18.  
  19. \begin{document}
  20. \begin{table}[H]
  21. \begin{tabularx}{\textwidth}{|p{0.1cm}X|m{2.5cm}|m{2.5cm}|m{2.5cm}|}
  22. \hline
  23. & \textbf{Fragen} & \centering{Antwort A} & \centering{Antwort B - braucht auch etwas mehr Platz} &
  24. \centering{Antwort C} \tabularnewline
  25. \hline
  26. c. & langer Text langer Text langer Text langer Text langer Text & \centering{1} & \centering{2} & \centering{3} \tabularnewline
  27. \hline
  28. d. & kurzer Text & \centering{1} & \centering{2} & \centering{3} \tabularnewline
  29. \hline
  30. e. & kurzer Text & \centering{1} & \centering{2} & \centering{3} \tabularnewline
  31. \hline
  32. f. & langer Text langer Text langer Text langer Text langer Text langer Text langer Text & \centering{1} & \centering{2} & \centering{3} \tabularnewline
  33. \hline
  34. \end{tabularx}
  35. \end{table}
  36.  
  37. \end{document}


Does anybody know how to solve this?

Thanks,
Richie

btw: sorry for the bad english, I hope you still get what i want to tell you :-)
Last edited by richi-rich on Tue Jul 30, 2013 3:03 pm, edited 1 time in total.

Tags:

User avatar
localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Tue Jul 30, 2013 11:05 am

Just for information to other users for awareness of possibly already existing solutions. The question has also been posted to MrUnix and GoLaTeX (two German forums, partly with answers). Please read what our administrator thinks about that.

Board Rules wrote:A crossposting is always contra-productive. But there is nothing really against it as long as it is mentioned. This means that a direct link has to be added. So other users who want to help are preserved from double efforts and waste of time.


What about trying it with the tabu package? Where are the difficulties when using its column specifications? Please give a corresponding minimal example if you have already tried it.


Best regards and welcome to the board
Thorsten
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

richi-rich
Posts: 4
Joined: Tue Jul 30, 2013 10:13 am

Postby richi-rich » Tue Jul 30, 2013 11:18 am

Hy,

thanks for clarification. I've cross-posted this here because in the german forum my question couldn't be answered.

To the topic:

I've tried it also with the tabu-package, the probleme here is the same, as you can see in this example:

  1. \documentclass[a4paper,14pt,BCOR10mm,oneside]{scrartcl}
  2. \usepackage[ngerman]{babel}
  3. \usepackage[utf8]{inputenc}
  4. \usepackage[babel,german=quotes]{csquotes}
  5. \usepackage[T1]{fontenc}
  6. \usepackage{tabularx}
  7. \usepackage[absolute,overlay]{textpos}
  8. \usepackage{wallpaper}
  9. \usepackage{tabu}
  10. \areaset{17cm}{26cm}
  11. \setlength{\topmargin}{-1.5cm}
  12. \setlength{\marginparwidth}{0.5cm}
  13.  
  14. \renewcommand{\familydefault}{\sfdefault}
  15. \usepackage{helvet}
  16.  
  17.  
  18.  
  19. \begin{document}
  20.  
  21. \tabulinesep=0.5ex
  22. \begin{table}[H]
  23. \begin{tabu} spread \linewidth {|p{0.1cm}X[m]|m{2.5cm}|m{2.5cm}|m{2.5cm}|}
  24. \hline
  25. & \textbf{Fragen} & \centering{Antwort A} & \centering{Antwort B - braucht auch etwas mehr Platz} &
  26. \centering{Antwort C} \tabularnewline
  27. \hline
  28. c.& langer Text langer Text langer Text langer Text langer Text & \centering{1} & \centering{2} & \centering{3} \tabularnewline
  29. \hline
  30. d. & kurzer Text & \centering{1} & \centering{2} & \centering{3} \tabularnewline
  31. \hline
  32. e. & kurzer Text & \centering{1} & \centering{2} & \centering{3} \tabularnewline
  33. \hline
  34. f. & langer Text langer Text langer Text langer Text langer Text langer Text langer Text & \centering{1} & \centering{2} & \centering{3} \tabularnewline
  35. \hline
  36. \end{tabu}
  37. \end{table}
  38.  
  39.  
  40. \end{document}


best regards
Richie

User avatar
cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Tue Jul 30, 2013 11:28 am

Hi Richie,

Welcome to the LaTeX community. I must confess it's not really clear to me what you want to achieve... However, since you apparently understand German you may be interested in this post on TeXwelt.de/wissen: Wie kann ich innerhalb einer Tabellenzelle vertikal zentrieren?. It explains how the vertical alignment of p{}-, m{}- and b{}-type columns works.

Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

richi-rich
Posts: 4
Joined: Tue Jul 30, 2013 10:13 am

Postby richi-rich » Tue Jul 30, 2013 11:53 am

Thanks for the link.

What I try to achieve is a table, that looks like this:

  1. a.xxxxxxxxx| | | |
  2. xxxxxxxxx| x | x | x |
  3. xxxxxxxxx| | | |
  4. ------------------------------------------
  5. b.xxxxxxxxx| | | |
  6. xxxxxxxxx| x | x | x |
  7. xxxxxxxxx| | | |
  8. ------------------------------------------


and so on...

best regards,
Richie

User avatar
cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Tue Jul 30, 2013 12:31 pm

Here's an idea: make the labels a., b., ... part of the full cells. Below I use a dummy first column and place the labels with \llap to the left of the first line of the full cells:

  1. \documentclass[a4paper,14pt,BCOR10mm,oneside]{scrartcl}
  2. \usepackage[ngerman]{babel}
  3. \usepackage[utf8]{inputenc}
  4. \usepackage[T1]{fontenc}
  5. \usepackage{tabularx}
  6. \usepackage{tabu}
  7.  
  8. \renewcommand{\familydefault}{\sfdefault}
  9. \usepackage{helvet}
  10.  
  11. \newcommand*\tablabel{%
  12. \stepcounter{tablabel}%
  13. \leavevmode
  14. \llap{\makebox[\tablabelwidth]{\thetablabel\hfil}\hspace*{\tablabelsep}}%
  15. }
  16. \newcounter{tablabel}
  17. \renewcommand*\thetablabel{\alph{tablabel}.}
  18. \newlength\tablabelsep
  19. \setlength\tablabelsep{1em}
  20. \newlength\tablabelwidth
  21. \setlength\tablabelwidth{1em}
  22.  
  23. \renewcommand{\tabularxcolumn}[1]{m{#1}}
  24.  
  25. \begin{document}
  26. \begin{table}
  27. \setcounter{tablabel}{2}
  28. \begin{tabu}{|X[1]X[10l,m]|X[5c,m]|X[5c,m]|X[5c,m]|}
  29. \hline
  30. & \textbf{Fragen}
  31. & Antwort A
  32. & Antwort B -- braucht auch etwas mehr Platz
  33. & Antwort C \\
  34. \hline
  35. & \tablabel langer Text langer Text langer Text langer Text langer Text
  36. & 1 & 2 & 3 \\
  37. \hline
  38. & \tablabel kurzer Text
  39. & 1 & 2 & 3 \\
  40. \hline
  41. & \tablabel kurzer Text
  42. & 1 & 2 & 3 \\
  43. \hline
  44. & \tablabel langer Text langer Text langer Text langer Text langer Text
  45. langer Text langer Text
  46. & 1 & 2 & 3 \\
  47. \hline
  48. \end{tabu}
  49. \end{table}
  50.  
  51. \end{document}


tabelle.png
tabelle.png (25.5 KiB) Viewed 14419 times


Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

richi-rich
Posts: 4
Joined: Tue Jul 30, 2013 10:13 am

Postby richi-rich » Tue Jul 30, 2013 3:02 pm

Hy,

This works well, also with arabic numbers using \arabic instead of \alpha

  1. \newcounter{tablabel}
  2. \renewcommand*\thetablabel{\arabic{tablabel}.}
  3. \newlength\tablabelsep
  4. \setlength\tablabelsep{1em}
  5. \newlength\tablabelwidth
  6. \setlength\tablabelwidth{1em}


Thanks for the help!

Regards
Richie


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 4 guests