1

How can I easily make the text and and images in my table be both horizontally and vertically aligned? I want every piece of content inside each cell to be placed in the middle.

I also want to remove the dots before my listed items, I tried [] next to \begin itemize but that didn't work.

Here are the table as it comes out with the current code (note that the images overlap the horizontal lines): Note that the images in the table overlap the \hline, which is not supposed to happen.

Here is the packages used for the document:

    \documentclass[twoside, openright, 12pt, a4paper]{book}

    \usepackage[T1]{fontenc}
    \usepackage[Swedish]{babel}
    \usepackage[utf8x]{inputenc}
    \usepackage[a4paper, margin=2cm]{geometry}
    \usepackage{color}
    \usepackage{graphicx}
    \usepackage{times}
    \usepackage{etoolbox}
    \usepackage{fancyhdr}
    \usepackage{enumitem}
    \usepackage{indentfirst}
    \usepackage{titlesec}
    \usepackage{hyperref}
    \usepackage{epstopdf}
    \usepackage{amsmath}
    \usepackage{subfigure}
    \usepackage{amssymb}
    \usepackage{epstopdf}
    \usepackage{enumitem}
    \usepackage{multirow}
    \usepackage{array}
    \usepackage{textcomp}
    \usepackage{gensymb}
    \usepackage{upgreek}
    \usepackage{float}
    %Paket som jag själv lagt in
    \usepackage{todonotes}
    \usepackage{mathtools}
    \usepackage{array}

    %\usepackage{tabularx}
    %\usepackage{titlesec}
    %\newcommand{\sectionbreak}{\clearpage}


    \renewcommand{\chaptername}{}

    \begin{document}

Here is the code I used for the table:

\begin{table}[H]

\caption{Upplag med symbol, förskjutningsvillkor och upplagskrafter. Förskjutning i horisontal- och vertikalled samt vinkeländring (rotation) betecknas med   $u$, $v$ respektive $\Theta$.}
\begin{center}
\begin{tabular}{| c | c | c | c |}
\hline
\textbf{Beteckning} & \textbf{Symbol} & \textbf{Förskjutningsvillkor} & \textbf{Upplagskrafter}\\
\hline
Fixlager
&
\includegraphics[width=0.08\textwidth]{Upplag2.PNG}
&
\begin{minipage}[t]{0.4\textwidth}
\begin{itemize}[]
\item $ u = 0$
\item $ v = 0$
\end{itemize}
\end{minipage}
&
\includegraphics[width=0.09\textwidth]{Upplag5.PNG}\\
\hline
Rullager
&
\includegraphics[width=0.14\textwidth]{Upplag1.PNG}
&
\begin{minipage}[t]{0.4\textwidth}
\begin{itemize}[]
\item $ v = 0$
\end{itemize}
\end{minipage}
&
\includegraphics[width=0.09\textwidth]{Upplag4.PNG}\\
\hline
Fast inspänning
&
\includegraphics[width=0.07\textwidth]{Upplag3.PNG}
&
\begin{minipage}[t]{0.4\textwidth}
\begin{itemize}[]
\item $ u = 0$
\item $ v = 0$
\item $ \Theta $
\end{itemize}
\end{minipage}
&
\includegraphics[width=0.09\textwidth]{Upplag6.PNG}\\
\hline

\end{tabular}
\end{center}
\end{table} 

\end{document}

Sincerely Emil Nilsson

  • 1
    Welcome to TeX.SX! Please help us (and also you) and add a minimal working example (MWE), that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass and ending with \end{document}. – Bobyandbob Apr 25 '18 at 8:54
  • 1
    And remember that we don't have your images. – remco Apr 25 '18 at 8:59
  • 2
    The compilable code isn't minimal and doesn't show your problem... @Bobyandbob gave you a link explaining the why and how of a minimal example. – remco Apr 25 '18 at 9:33
  • Welcome to TeX.SE! Spend half an hour and follow remco's links. This will save you lots of time in the future and will mãe your questions more likely to get formidable and helpful answers. Also, there is a nice online tool to help you make latex tables. I will post the link here. And try avoiding vertical lines in tables, unless they are absolutely necessary. Hint: they never are, cf. booktabs documentation on ctan. – thymaro Apr 26 '18 at 6:44
4

If you don't want any kind of label for the list in the 3rd column, it is not really a list, so I suggest to use a \makecell command, which allows for line breaks in standard cells. You can define the horizontal and vertical alignment of the contents (default is cc). To centre the images, adjustbox has an \adjincludegraphics command which accepts a valign key. Finally; we must add some vertical padding to cells so the images do not touch the horizontal lines. The cellspace cares for this, defining minimal padding at the top and bottom of cells.

Thus I propose this code:

    \documentclass[twoside, 12pt, a4paper, swedish]{book}
    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage{newtxtext, newtxmath} 
    \usepackage[a4paper, margin=2cm]{geometry}
    \usepackage{babel} 
    \usepackage[demo]{adjustbox}
   \usepackage{float, caption, makecell, cellspace}
    \setlength{\cellspacetoplimit}{4pt}
    \setlength{\cellspacebottomlimit}{4pt}

    \begin{document}

    \begin{table}[H]
    \renewcommand{\cellalign}{lc}
    \adjustboxset{valign=c}
    \caption{Upplag med symbol, förskjutningsvillkor och upplagskrafter. Förskjutning i horisontal- och vertikalled samt vinkeländring (rotation) betecknas med $u$, $v$ respektive $\Theta$.}
    \centering
    \begin{tabular}{| Sc | Sc | Sl | Sc |}
    \hline
    \textbf{Beteckning} & \textbf{Symbol} & \textbf{Förskjutningsvillkor} & \textbf{Upplagskrafter}\\
    \hline
    Fixlager
    & \adjincludegraphics[width=0.08\textwidth]{Upplag2.PNG}
    &
   $ \makecell{ u = 0\\ v = 0} $
    & \adjincludegraphics[width=0.09\textwidth]{Upplag5.PNG}\\
    \hline
    Rullager
    & \adjincludegraphics[width=0.14\textwidth]{Upplag1.PNG}
    & $ v = 0$
    & \adjincludegraphics[width=0.09\textwidth]{Upplag4.PNG}\\
    \hline
    Fast inspänning
    & \adjincludegraphics[width=0.07\textwidth]{Upplag3.PNG}
    & $ \makecell{ u = 0 \\ v = 0 \\ \Theta} $
    & \adjincludegraphics[width=0.09\textwidth]{Upplag6.PNG}\\
    \hline
    \end{tabular}
    \end{table}

    \end{document} 

enter image description here

Unrelated note: You load some obsolete packages: times doesn't have maths support, so any formula will be typed with Computer Modern, and the mixture of fonts looks hideous. In my code I replaced it with newtxtext, newtxmath, based on a Times clone:TeX Gyre Termes.

The subfigure package too is obsolete and no more maintained. You should use the subfigure environment, from subcaption.

Last, you don't have to load amsmath when you load mathtools since the latter does it for you, hyperref should be loaded as the last package (on exception cleveref should be loaded afterwards). And don't load packages twice!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.