5

I'm trying to get the vertical alignment for the first column but I'm having some troubles.

Here is a pic of what it looks like right now: enter image description here

Here is the code:

\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

\begin{tabulary}{\linewidth}{| >{\bfseries}M{6cm} | L |}
  \hline
  Modulo - Lezione - Unità & Primo - La Scacchiera - Uno \\ \hline
  Numero Pagine &  \\ \hline
  Descrizione & Questa unità mostra qual è la posizione corretta dei pezzi sulla scacchiera. Di seguito la preparazione dello studente verrà verificata mediante appositi esercizi.\\ \hline
  Numero Immagini & \\ \hline
  Numero Video & \\ \hline
  Numero Audio & \\ \hline
  Strumenti di Comunicazione & \\ \hline
\end{tabulary}

I've also tried using "m" in the table definition but it still does not work.

[Edit]: I'm looking for an alignment of the first column in which, for example, the word "Descrizione" is shown in the middle of the box like shown below:

enter image description here

6
  • Welcome to TeX.Stackexchange! Without minimal working example and without telling us, which vertical alignment for the first column you expect, it is hard to help. However, maybe you want a m column for the second column. Even packages makecell and multirow could be useful, depending on what the result should be.
    – cabohah
    Commented Apr 28, 2023 at 9:24
  • hi @cabohah, thank you! I edited the question for further informations, thanks again Commented Apr 28, 2023 at 9:29
  • Still waiting for the minimal working example, and still thinking, you want a m or M for the second column.
    – cabohah
    Commented Apr 28, 2023 at 9:30
  • I added a working example. Anyway I do not understand why you say I want it for the second column, I said for the first column. Anyway I tried with makecell but I should use the command for every row and I was looking for a universal command to define the table. Commented Apr 28, 2023 at 9:37
  • 1
    No, you've not added a working example but only a code snippet. A working example usually starts with \documentclass and ends with \end{document}. Please see the already linked page.
    – cabohah
    Commented Apr 28, 2023 at 9:38

2 Answers 2

3

As already explained in a comment, you need m for the second column not the first one, e.g.

\documentclass{article}

\usepackage{tabularx}
\renewcommand*{\tabularxcolumn}[1]{m{#1}}% use m-columns for X-columns

\begin{document}

\begin{tabularx}{\linewidth}{|>{\bfseries}c|X|}
  \hline
  Modulo - Lezione - Unità & Primo - La Scacchiera - Uno \\ \hline
  Numero Pagine &  \\ \hline
  Descrizione & Questa unità mostra qual è la posizione corretta dei pezzi sulla scacchiera. Di seguito la preparazione dello studente verrà verificata mediante appositi esercizi.\\ \hline
  Numero Immagini & \\ \hline
  Numero Video & \\ \hline
  Numero Audio & \\ \hline
  Strumenti di Comunicazione & \\ \hline
\end{tabularx}

\end{document}

enter image description here

3
  • Thank you, might I ask why you need to code the second column to define the first column? I'm new to latex and I'm trying to learn Commented Apr 28, 2023 at 9:39
  • @alessandro_pier Because you want align the middle of the cell of the second column to the baseline of the row not the first one. See also similar questions like tex.stackexchange.com/q/395356/277964 BTW: Using package tabularray could also be useful. And removing all the vertical lines and most of the horizontal could improve the typography. But this would be another question …
    – cabohah
    Commented Apr 28, 2023 at 9:45
  • Here's a nice intro: en.wikibooks.org/wiki/LaTeX/Tables . As a beginner, I suggest to scan rather than reading word by word. Try getting the big picture.
    – MS-SPO
    Commented Apr 28, 2023 at 10:01
3

You can define a variant of tabularx that sets X columns with middle vertical alignment.

But it's better to avoid all those unnecessary rules, see the second realization of the table where

  1. the first column has left alignment;
  2. there's no padding at either end;
  3. there are no rules;
  4. prepositions have been added and capitalization removed as it's usual in Italian.

You can see that the natural position of “Descrizione” is at the top and I contend it's better also if you insist with caged tables.

\documentclass[a4paper]{article}
\usepackage{tabularx}

\usepackage{booktabs} % for the second solution

\newenvironment{mtabularx}{%
  \renewcommand{\tabularxcolumn}[1]{m{##1}}\tabularx
}{\endtabularx}

\begin{document}

\section{With rules}

\noindent
\begin{mtabularx}{\textwidth}{|>{\bfseries}c|X|}
 \hline
  Modulo - Lezione - Unità & Primo - La Scacchiera - Uno \\ \hline
  Numero Pagine &  \\ \hline
  Descrizione & Questa unità mostra qual è la posizione corretta dei pezzi 
                sulla scacchiera. Di seguito la preparazione dello studente
                verrà verificata mediante appositi esercizi.\\ \hline
  Numero Immagini & \\ \hline
  Numero Video & \\ \hline
  Numero Audio & \\ \hline
  Strumenti di Comunicazione & \\ \hline
\end{mtabularx}

\section{Without unnecessary rules}

\noindent
\begin{tabularx}{\textwidth}{@{}>{\bfseries}lX@{}}
\toprule
  Modulo - Lezione - Unità & Primo - La Scacchiera - Uno \\
\addlinespace
  Numero di pagine & 17 \\
\addlinespace
  Descrizione & Questa unità mostra qual è la posizione corretta dei pezzi
                sulla scacchiera. Di seguito la preparazione dello studente
                verrà verificata mediante appositi esercizi.\\
\addlinespace
  Numero di immagini & 42 \\
\addlinespace
  Numero dei video & 23 \\
\addlinespace
  Numero degli audio & 12 \\
\addlinespace
  Strumenti di comunicazione & Vattelapesca \\
\bottomrule
\end{tabularx}

\end{document}

enter image description here

You must log in to answer this question.

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