Crea una tabella di celle unite con più righe

Aug 15 2020

Vorrei creare delle "schede descrittive" come queste in latex con tabelle. Ma non ho trovato un buon modo per crearli.

L'idea di base è creare un'intestazione di colonna variabile (più di 2, nel caso sia necessario) con una grande casella di testo sottostante, che idealmente supporta le immagini.

Qual è un buon modo per farlo?

Risposte

3 leandriis Aug 15 2020 at 16:55

Probabilmente quanto segue può aiutarti a iniziare. Dettagli come la spaziatura e l'allineamento possono ovviamente essere regolati in base alle proprie esigenze.

\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum} % for dummy text
\begin{document}
\noindent
\begin{tabular}{*{2}{|p{\dimexpr 0.5\textwidth-2\tabcolsep}}|}
\hline
\bfseries text & \bfseries other text\\
\hline
\multicolumn{2}{|p{\dimexpr \textwidth-2\tabcolsep}|}{\lipsum[1]}\\
\hline
\end{tabular}

\noindent
\begin{tabular}{*{2}{|p{\dimexpr 0.5\textwidth-2\tabcolsep}}|}
\hline
\bfseries text & \bfseries other text\\
\hline
\multicolumn{2}{|p{\dimexpr \textwidth-2\tabcolsep}|}{\includegraphics[width=2cm]{example-image}

\lipsum[1]}
\\
\hline
\end{tabular}

\noindent
\begin{tabular}{*{4}{|p{\dimexpr 0.25\textwidth-2\tabcolsep}}|}
\hline
\bfseries text & \bfseries other text &\bfseries text & \bfseries other text\\
\hline
\multicolumn{4}{|p{\dimexpr \textwidth-2\tabcolsep}|}{\lipsum[1]}\\
\hline
\end{tabular}
\end{document}
4 Zarko Aug 15 2020 at 16:49


\documentclass{article}
\usepackage{makecell,tabularx}
\setcellgapes{3pt}
\makegapedcells
\setlength\parindent{0pt}

\usepackage{lipsum}

\begin{document}
\begin{tabularx}{\linewidth}{|X|X|}
    \hline
text text   &   text text text  \\
    \hline
\multicolumn{2}{|>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth}X|}
            {\lipsum[1]}        \\
    \hline
\end{tabularx}
\end{document}
3 Mico Aug 15 2020 at 16:56

Ecco una soluzione che crea una macro chiamata \mergedtabche accetta tre argomenti.

\documentclass{article}
\usepackage{lipsum}
\usepackage{tabularx}
\newcolumntype{Y}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax}X}

\newcommand{\mergedtab}[3]{%
   \par\bigskip\noindent
   \begingroup
   \setlength\extrarowheight{2pt}
   \frenchspacing
   \begin{tabularx}{\textwidth}{|X|X|}
   \hline
   #1 & #2 \\
   \hline
   \multicolumn{2}{|Y|}{#3} \\
   \hline
   \end{tabularx}\endgroup\par\bigskip}
  
\begin{document}
\mergedtab{Donaudampf\dots}{/naval/rivers/donau/\dots}{\lipsum[2]}
\end{document}