1

I'm having issues trying to align all the text at the top of my cells. Indeed, it looks like because of the \makecell I am using, the text beside is not where it should be. I have tried a lot of suggestions from other questions and sites, but nothing is working. Here is an example of my table and the result. We see the first column is not at the top even if I chose "p{}" in my table.

\documentclass{article}

% Language setting
% Replace `english' with e.g. `spanish' to change the document language
\usepackage[english]{babel}

% Set page size and margins
% Replace `letterpaper' with`a4paper' for UK/EU standard size
\usepackage[letterpaper,top=2cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}

% Useful packages
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage{multirow}
\usepackage{makecell}
\title{Your Paper}
\author{You}

\begin{document}
\begin{tabular}{|p{4cm}|p{5cm}|p{4cm}|}
\hline
\multicolumn{3}{|c|}{Title} \\
\hline
Programmation un simulateur complet du système &\makecell[l]{Oui/Non pour chaque item: \\ Corde \\ Actionneur d'entretien \\Capteur (optique) \\ Conditionnement des signaux  \\ Mesure de la fréquence  \\ Méthode d'accord  \\ Contrôleur d'accord}& Chacun des éléments du système doit être simulé dans un module indépendant \\     \hline
\end{tabular}

\end{document}

The problem is in the first column

2
  • Welcome to TeX.SE! Try to set makecell option to tl: \makecell[tl]{Oui/Non ,,,}. You also may consider to use some list (for example itemize) instead of `makecell for second row content.
    – Zarko
    Jan 30 at 22:41
  • Oh yes! Thank you so much, I searched for hours. :)
    – Pollen
    Jan 30 at 22:49

2 Answers 2

0

The \makecell command hah option for horizontal (c,lr) and vertical (b, c, r) positioning, so in your case makecell[tl]{Oui/Non ,,,} should do what you after.

As I mentioned in comment, you may consider for items in the second column to use itemize list. Beside this, use of tblr of tabularray package enable to write nice table. Of course you can use itemize also in tabular table, but formating of itemize is less simple:

\documentclass{article}
\usepackage[letterpaper,
            vmargin=2cm, hmargin=3cm,
            marginparwidth=1.75cm]{geometry}
\usepackage[english]{babel}

% Useful packages
\usepackage{enumitem}
\usepackage{ragged2e}
\usepackage{tabularray}
    \UseTblrLibrary{varwidth}
\usepackage[colorlinks=true, 
            allcolors=blue]{hyperref} % had to be last in in preamble

\title{Your Paper}
\author{You}

\begin{document}
\begin{tblr}{hlines, vlines,
             colspec = {Q[l,wd=4cm] Q[l, wd=5cm] Q[l, wd=4cm]},
             stretch = -1,%<--- remove extra space above and below lists
             measure = vbox,
             }
\SetCell[c=3]{c}    Title       
    &   &                       \\
Programmation un simulateur complet du système 
    &   Oui/Non pour chaque item: 
        \begin{itemize}[nosep, leftmargin=*]
    \item   Corde 
    \item   Actionneur d'entretien 
    \item   Capteur (optique) 
    \item   Conditionnement des signaux  
    \item   Mesure de la fréquence  
    \item   Méthode d'accord 
    \item   Contrôleur d'accord
        \end{itemize}
        &   Chacun des éléments du système doit être 
            simulé dans un module indépendant \\
\end{tblr}
\end{document}

enter image description here

If you for some reason not like to have bullets before items in list, or change it for example to dash, than just change options of `itemize accordingly. For example:

  • \begin{itemize}[nosep, label={}, leftmargin=*] for no bullets
  • \begin{itemize}[nosep, label=-, leftmargin=*] for dash instead of bullets
  • etc

Addendum:
Regarding OP comment:

  • Question has tag longtable, but in it is not given any information about this or if the extension it to span several pages is an issues.

  • For long table are developed special tables package as are longtable, xltabular, longtblr of tabularray package, etc.

  • For design of long tables should be known (at least) the following:

    • will table has captions (on the top of each part of table)
    • how many table rows contain column headers and should be repeated at the top of each table part
  • Your table structure is not very clear (does it has column headers, what is purpose of the multi column cell).

  • Use long table you should be aware, that long tables can be broken only between rows. In cases when cells content has many lines (like list in the second column of your table) ca hepen that below table parts you will a lot of empty space.

  • An example of long table using longtblr table is:

\documentclass{article}
\usepackage[letterpaper,
            vmargin=2cm, hmargin=3cm,
            marginparwidth=1.75cm]{geometry}
\usepackage[english]{babel}

\usepackage{lipsum} % dummy text filler
% Useful packages
\usepackage{enumitem}
\usepackage{ragged2e}
\usepackage{tabularray}
    \UseTblrLibrary{varwidth}
\usepackage[colorlinks=true, 
            allcolors=blue]{hyperref} % had to be last in in preamble

\title{Your Paper}
\author{You}

\begin{document}
\maketitle

\lipsum[1-3]
\begingroup
    \SetTblrStyle{caption}{font=\small}
    \SetTblrStyle{caption-tag}{font=\bfseries}
%
    \setlist[itemize]{nosep, topsep=0.5ex, leftmargin=*}
\begin{longtblr}[
caption = {From question is not evident, if your table should have caption or not.},
  label = {tab:long}, 
                ]{rowhead = 1,
                  colspec = {Q[l,wd=4cm] Q[l, wd=5cm] Q[l, wd=4cm]},
                  stretch = -1,%<--- remove extra space above and below lists
                  measure = vbox,
                  row{1} = {font=\bfseries},
                  hlines, vlines,
                }
column header
    & column header
        & column header                 \\
Programmation un simulateur complet du système 
    &   Oui/Non pour chaque item: 
        \begin{itemize}
    \item   Corde 
    \item   Actionneur d'entretien 
    \item   Capteur (optique) 
    \item   Conditionnement des signaux  
    \item   Mesure de la fréquence  
    \item   Méthode d'accord 
    \item   Contrôleur d'accord
        \end{itemize}
        &   Chacun des éléments du système doit être 
            simulé dans un module indépendant \\
Programmation un simulateur complet du système
    &   Oui/Non pour chaque item:
        \begin{itemize}
    \item   Corde
    \item   Actionneur d'entretien
    \item   Capteur (optique)
    \item   Conditionnement des signaux
    \item   Mesure de la fréquence
    \item   Méthode d'accord
    \item   Contrôleur d'accord
        \end{itemize}
        &   Chacun des éléments du système doit être
            simulé dans un module indépendant \\
Programmation un simulateur complet du système
    &   Oui/Non pour chaque item:
        \begin{itemize}
    \item   Corde
    \item   Actionneur d'entretien
    \item   Capteur (optique)
    \item   Conditionnement des signaux
    \item   Mesure de la fréquence
    \item   Méthode d'accord
    \item   Contrôleur d'accord
        \end{itemize}
        &   Chacun des éléments du système doit être
            simulé dans un module indépendant \\
\end{longtblr}
\endgroup
\end{document}

enter image description here

3
  • Thank you for your help, I use itemize like recommended, but I must use longtable because my table is on 3 pages. Thus, I can't have a result as good as you, but I'm statisfied.
    – Pollen
    Jan 31 at 2:23
  • @Pollen, it is not a big problem to extend to long table, however in your question is not indicated this. tabular can not be extended to over more pages, for this you need longtable or longtblt.. I extend my answer with this option.
    – Zarko
    Jan 31 at 7:12
  • Yes, I'm using longtable, I just forgot I simplified my code and wrote tabular instead. I remove the tag since I discovered that my problem is not related to this. Like I said, I'm satisfied with the result I have now, so I prefer to keep it like this for now. Thank you again
    – Pollen
    Jan 31 at 20:11
0

You don't need \makecell.

\documentclass{article}
\usepackage{array}

\usepackage{tabularx} % for the second solution
\usepackage{booktabs} % for the third solution (with also tabularx)

\begin{document}

\begin{center}

\begin{tabular}{|>{\raggedright}p{4cm}|p{5cm}|>{\raggedright\arraybackslash}p{4cm}|}
\hline
\multicolumn{3}{|c|}{Title} \\
\hline
Programmation un simulateur complet du système &
  Oui/Non pour chaque item: \newline
  Corde \newline
  Actionneur d'entretien \newline
  Capteur (optique) \newline
  Conditionnement des signaux \newline
  Mesure de la fréquence \newline
  Méthode d'accord \newline
  Contrôleur d'accord &
  Chacun des éléments du système doit être simulé dans un module indépendant \\
\hline
\end{tabular}

\bigskip

% this has no overfull
\begin{tabularx}{\textwidth}{|>{\raggedright}X | c | >{\raggedright\arraybackslash}X|}
\hline
\multicolumn{3}{|c|}{Title} \\
\hline
Programmation un simulateur complet du système &
  \begin{tabular}[t]{@{}l@{}}
  Oui/Non pour chaque item: \\
  Corde \\
  Actionneur d'entretien \\
  Capteur (optique) \\
  Conditionnement des signaux \\
  Mesure de la fréquence \\
  Méthode d'accord \\
  Contrôleur d'accord
  \end{tabular} &
  Chacun des éléments du système doit être simulé dans un module indépendant \\
\hline
\end{tabularx}

\bigskip

\begin{tabularx}{\textwidth}{@{}>{\raggedright}X c >{\raggedright\arraybackslash}X@{}}
\toprule
\multicolumn{3}{c}{Title} \\
\midrule
Programmation un simulateur complet du système &
  \begin{tabular}[t]{@{}l@{}}
  Oui/Non pour chaque item: \\
  Corde \\
  Actionneur d'entretien \\
  Capteur (optique) \\
  Conditionnement des signaux \\
  Mesure de la fréquence \\
  Méthode d'accord \\
  Contrôleur d'accord
  \end{tabular} &
  Chacun des éléments du système doit être simulé dans un module indépendant \\
\bottomrule
\end{tabularx}

\end{center}

\end{document}

enter image description here

The last two tables don't overfill the text width.

You must log in to answer this question.

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