3

I've got a little question about my tabular vertical aligment. I've a two-column tabular with letter and text :

\begin{tabular}{p{0.1\textwidth} p{0.8\textwidth} }

Hypothèse   &   Description\\
\hline

But in my pdf file, the first and second column is not aligned. I tried to align everything to the top, to insert space with \\[1ex], but nothing seems to work!

My Example of not aligned text

In fact, the problem seems to come from the counter I use to enumerate the letters :

\newcounter{hypothese}
\renewcommand\thehypothese{\Alph{hypothese}}
\newcommand{\newhypothese}[1]{\refstepcounter{hypothese}\label{#1} \ref{#1}}

\footnotesize


\begin{tabular}{p{0.1\textwidth} p{0.8\textwidth} }

Hypothèse   &   Description\\
\hline
\hspace{1pc}&\

\multicolumn{2}{p{\textwidth}}{\textbf{Multimodalité}} \\
A & Bla bla Bla blaBla blaBla blaBla blaBla blaBla blaBla blaBla blaBla blaBla bla Bla bla Bla bla\\
B &Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla \\
C& Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla  \\
D& Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla \\
% Upon here, everything looks right... below here, first column are not aligned right.
\newhypothese{hypo:cla_ver} &Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla \\
\newhypothese{hypo:com_acc_recoup} & Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla \\
\newhypothese{hypo:reg_negoc} & Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla \\
\newhypothese{hypo:reg_croise} & LBla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla \\
\newhypothese{hypo:gest_reg_part} & Bla bla Bla bla Bla bla \\
\newhypothese{hypo:gest_verba} & Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla \\
\newhypothese{hypo:trace_graph_verba} & Bla bla Bla bla Bla bla \

But I don't know how to fix it

6
  • meta.tex.stackexchange.com/questions/1436/welcome-to-tex-sx. Can you provide a complete MWE.
    – cacamailg
    May 6, 2013 at 17:48
  • @cacamailg : Here's part of my code that mess things up : pastebin.com/6hzpwNhv May 6, 2013 at 17:56
  • It would be better if you build a MWE herein, for us to test your code. Nevertheless, why are you using \hspace{1pc} after the tabular.
    – cacamailg
    May 6, 2013 at 18:02
  • Also you are using a multicolumn of \textwidth after you have defined two columns, one of 0.1\textwidth and other of 0.8\textwidth. Which is not a good practice.
    – cacamailg
    May 6, 2013 at 18:07
  • I used it \hspace to add vertical space below my \hline. May 6, 2013 at 18:28

3 Answers 3

2

You can profit from the tabularx package, so you don't have to fiddle with the subtle points of the interaction between issuing \label and printing \thehypothese

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{tabularx,booktabs}

\newcounter{hypothese}
\renewcommand\thehypothese{\Alph{hypothese}}
\newcommand{\newhypothese}[1]{%
  \refstepcounter{hypothese}\label{#1}\thehypothese}

\begin{document}

\noindent
\begin{tabularx}{\textwidth}{lX}
Hypothèse   &   Description\\
\midrule
\multicolumn{2}{l}{\textbf{Multimodalité}} \\
\newhypothese{hypo:cla_ver} &New hypothese: Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla \\
\newhypothese{hypo:com_acc_recoup} & Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla \\
\newhypothese{hypo:reg_negoc} & Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla \\
\newhypothese{hypo:reg_croise} & LBla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla \\
\newhypothese{hypo:gest_reg_part} & Bla bla Bla bla Bla bla \\
\newhypothese{hypo:gest_verba} & Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla \\
\newhypothese{hypo:trace_graph_verba} & Bla bla Bla bla Bla bla \\
\end{tabularx}

\end{document}

enter image description here

1

The problem seems to come from this command not starting with any printing material. In particular, \label uses internal commands \@bsphack and \@espack which successfully gobble the correct number of spaces before and after when the command is in ordinary text, i.e. horizontal mode, but which do not necessarily do the right thing in between paragraphs, i.e. in vertical mode. (See source2e pages 52--53 for a discussion of possible modifications of these commands.) In many situtations, including your case, you can fix this simply by forcing horizontal mode via \leavevmode:

Sample output

\documentclass{article}

\begin{document}
\newcounter{hypothese}
\renewcommand\thehypothese{\Alph{hypothese}}
\newcommand{\newhypothese}[1]{\leavevmode\refstepcounter{hypothese}\label{#1}\ref{#1}}

\begin{tabular}{p{0.1\textwidth} p{0.8\textwidth} }
Hypothèse   &   Description\\
\hline
\hspace{1pc}&\\
\multicolumn{2}{p{\textwidth}}{\textbf{Multimodalité}} \\
A &Ordinary label: Bla bla Bla blaBla blaBla blaBla blaBla blaBla blaBla blaBla blaBla blaBla bla Bla bla Bla bla\\
B &Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla \\
\newhypothese{hypo:cla_ver} &New hypothese: Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla \\
\newhypothese{hypo:com_acc_recoup} & Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla \\
\newhypothese{hypo:reg_negoc} & Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla \\
\newhypothese{hypo:reg_croise} & LBla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla \\
\newhypothese{hypo:gest_reg_part} & Bla bla Bla bla Bla bla \\
\newhypothese{hypo:gest_verba} & Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla Bla bla \\
\newhypothese{hypo:trace_graph_verba} & Bla bla Bla bla Bla bla \\
\end{tabular}
\end{document}
1
  • Thanks for the answers. The solution I found below seems to work for now, but i'll look at yours if it turns out it doesn't. May 6, 2013 at 23:37
0

I found the solution. By juste replacing

\newcommand{\newhypothese}[1]{\refstepcounter{hypothese}\label{#1} \ref{#1}}

by

\newcommand{\newhypothese}[1]{\refstepcounter{hypothese}\thehypothese\label{#1}}

It looks perfect... I don't know why. Thanks anyway

3
  • That doesn't work, as your labels are no longer defined, and your label is now doubled. Deleting the .aux file and compiling again will give you problems... May 6, 2013 at 19:37
  • Oh, sorry, my bad... I replaced the line by \newcommand{\newhypothese}[1]{\refstepcounter{hypothese}\thehypothese \label{#1}} May 6, 2013 at 23:35
  • OK - I have updated my answer accordingly with some explanation. Your rewriting introduces printed material before the \label so the \label command is now in horizontal mode. May 7, 2013 at 7:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .