1

I have a very urgent matter and I've read so many threads and tried to combine the answers but nothing works or it gets much uglier... I just want to show up my figure and the text in a table in a nice way. The images cover the lines and aren't vertical aligned...

Sorry for the german language but i got no time to make a simple example in english out of it

I have the following code

\begin{table}[h]
    \centering
    \begin{tabular}{l|l|l|}
    \cline{2-3}
        & \textbf{Konflikttyp}
        & \textbf{Kollisionsarten} \\ 
        \hline
    \multicolumn{1}{|l|}{
    \parbox[c]{1em}{\includegraphics[width=50mm]{./Abbildungen/Auffahren.jpg}}
    \label{fig:Auffahren}}  
    & Auffahren                                                           
    & \tabitem Auffahrunfall\\
    \hline
    \multicolumn{1}{|l|}{
    \includegraphics[width=50mm]{./Abbildungen/Fahrstreifenwechsel.jpg}
    \label{fig:Fahrstreifenwechsel}} 
    & Fahrstreifenwechsel                                                 
    & \begin{tabular}[c]{@{}l@{}}
        \tabitem Auffahrunfall\\
        \tabitem Seitenkollision (wenn die Seite ei-\\
         \quad \thinspace nes Fahrzeuges im Längsverkehr\\
         \quad \thinspace mit der Seite eines anderen\\ 
         \quad \thinspace Fahrzeugs kollidieren würde)
    \end{tabular} \\ 
    \hline
    \end{tabular}
    \caption[Konfliktszenarien mit zugehörigen Kollisionsarten]{Konfliktszenarien mit zugehörigen Kollisionsarten nach \textsc{Wang} und \textsc{Stamatiadis} \cite{Wang.2013}  \label{tab:Konfliktszenarios}}
\end{table}

It provides the following output: generated table

2
  • 1
    tex.stackexchange.com/a/550474/134144 should give you an idea on how you can combine cellspace and adjustbox to your advantage.
    – leandriis
    Oct 9, 2020 at 9:50
  • @leandriis thanks for the hint but the first images still covers the upper \hline. I will look up for a way to adjust the cell height...
    – QuagTeX
    Oct 9, 2020 at 10:01

2 Answers 2

2

A small variation of nice @leandriis answer (+1).

Since you not provide any information about your document design (used documentclass, page layout, relevant package in your document preamble), both answer are faced by guessing about this, we both used a documentclass and preamble according to our taste, what a beautiful table:

In MWE below:

  • the table position option [h] is changed to the more correct [ht] (now table can migrate to the top of the next page)
  • for table is used tabularx because it enables to prescribe table width automatic determination of X column widths
  • for better formatting of text in the last columns, the X column type is modified to >{RaggedRight}X (RaggedRight is defined in the ragged2e package), which enable "smart" aligning of cells' contents to the left
  • for column headers is used \thead command defined in the makecell command
  • is exploited features of the adjustbox package for moving image baseline to top of images, adding vertical spaces around images and inserting images by use of the \adjustimage command
  • for lists in the third column is used the itemize package and its ability for their customization
  • for list customization is employed \AtBeginEnvironment{...}{...} environment from the etoolbox package
\documentclass{article}
\usepackage{geometry}
\usepackage{ragged2e}
\usepackage{makecell, tabularx}
\renewcommand\theadfont{\normalsize\bfseries}
\usepackage[demo,               % remove demo option in actual document
            export]{adjustbox}  % it load graphicx too
\usepackage{enumitem}
\usepackage{etoolbox}
\AtBeginEnvironment{table}%
{%
\setlist[itemize]{nosep,
                 leftmargin=*,
                 label=\textbullet,
                 after=\end{minipage},                  % <---
                 before=\begin{minipage}[t]{\linewidth} % <---
                 }
}

\begin{document}
    \begin{table}[ht] % <---
    \centering
    \adjustboxset{width=50mm,valign=t, margin=0pt 6pt 0pt 6pt} % <---
\begin{tabularx}{\textwidth}{|l|l|>{\RaggedRight}X|}
    \cline{2-3}
\multicolumn{1}{c|}{} 
    & \thead[l]{Konflikttyp}
        & \thead[l]{Kollisionsarten} \\
    \hline
\adjustimage{}{./Abbildungen/Auffahren}
    & Auffahren
        &   \begin{itemize} 
            \item Auffahrunfall 
            \end{itemize} \\
    \hline
\adjustimage{}{./Abbildungen/Fahrstreifenwechsel}
%    \label{fig:Fahrstreifenwechsel} % this label does not make sense since the image does nt have its own figure number and caption.
    & Fahrstreifenwechsel
        &   \begin{itemize}
              \item  Auffahrunfall
              \item Seitenkollision (wenn die Seite eines Fahrzeuges im Längsverkehr mit der Seite eines anderen Fahrzeugs kollidieren würde)
            \end{itemize}\\
    \hline
\end{tabularx}
\caption[Konfliktszenarien mit zugehörigen Kollisionsarten]{Konfliktszenarien mit zugehörigen Kollisionsarten nach \textsc{Wang} und \textsc{Stamatiadis} \cite{Wang.2013}  
\label{tab:Konfliktszenarios}}
    \end{table}
\end{document}

enter image description here

2

The following should serve as a point to start from:

enter image description here

\documentclass{article}
\usepackage{geometry}
\usepackage[demo]{graphicx} % remove demo option in actual document
\usepackage{tabularx}
\usepackage[column=0]{cellspace}
\usepackage[export]{adjustbox}
\usepackage{enumitem}

\setlength{\cellspacetoplimit}{\tabcolsep}
\setlength{\cellspacebottomlimit}{\cellspacetoplimit}
\addparagraphcolumntypes{X}

\newlist{tabitemize}{itemize}{1}
\setlist[tabitemize]{label=\textbullet,nosep,after=\strut,align=parleft,leftmargin=*,before={\begin{minipage}[t]{\hsize}}, after={\end{minipage}}}


\begin{document}

\begin{table}[h]
    \centering
    \begin{tabularx}{\textwidth}{|0l|0l|0{X}|}
    \cline{2-3}
       \multicolumn{1}{c|}{} & \textbf{Konflikttyp}
        & \textbf{Kollisionsarten} \\ 
        \hline
    \includegraphics[width=50mm,valign=t]{./Abbildungen/Auffahren.jpg}
%    \label{fig:Auffahren}  % this label does not make sense since the image does nt have its own figure number and caption.
    & Auffahren                                                           
    & \begin{tabitemize} \item Auffahrunfall \end{tabitemize} \\
    \hline
    \includegraphics[width=50mm,valign=t]{./Abbildungen/Fahrstreifenwechsel.jpg}
%    \label{fig:Fahrstreifenwechsel} % this label does not make sense since the image does nt have its own figure number and caption.
    & Fahrstreifenwechsel                                                 
    & \begin{tabitemize} 
          \item  Auffahrunfall
          \item Seitenkollision (wenn die Seite eines Fahrzeuges im Längsverkehr mit der Seite eines anderen Fahrzeugs kollidieren würde)
      \end{tabitemize}\\
    \hline
    \end{tabularx}
    \caption[Konfliktszenarien mit zugehörigen Kollisionsarten]{Konfliktszenarien mit zugehörigen Kollisionsarten nach \textsc{Wang} und \textsc{Stamatiadis} \cite{Wang.2013}  \label{tab:Konfliktszenarios}}
\end{table}


\end{document}
3
  • that worked fine but it messed up the page layout somehow and a way i can't really see in the PDF. My page numbers went from 76 to 81
    – QuagTeX
    Oct 9, 2020 at 10:14
  • ist there also a way doing it with tabular instead of tabularx?
    – QuagTeX
    Oct 9, 2020 at 12:42
  • 2
    Since you did not provide the documentclass or any information about the packages you load, I can't tell you what went wrong. Regarding your second quwstion: yes, you can also use a regular tabular. To do so, replace the X type column with a fixed width p type column of the appropriate width.
    – leandriis
    Oct 9, 2020 at 13:18

You must log in to answer this question.

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