Rotate table and image with caption in LaTeX

In the previous tutorial, I explain how to rotate a table and image in LaTeX. But in this tutorial, I will show you how to rotate a table or image including the caption in LaTeX.

Rotate a table and image including the caption with minipage

In LaTeX, generally, we use \adjustbox or \rotatebox command to rotate a table or image. But you can’t rotate the caption directly with this command. In this case, you have to use the minipage environment and rotate the minipage, not the table. Like this.

\begin{table}

\rotatebox{<angle>}{
\begin{minipage}{0.5\textwidth}
\centering
\begin{tabular}{}
...
\end{tabular}
\caption{<Your caption>}
\end{minipage}
}

\end{table}

Similar Process for the image.

\begin{figure}

\rotatebox{<angle>}{
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[]{<image-file>}
\caption{<Your caption>}
\end{minipage}
}

\end{figure}

\documentclass{article}
\usepackage{float} % To fix floating objects
\usepackage{graphicx} 

\begin{document}

Rotate an table with caption in \LaTeX :\\[4pt]
\begin{table}[H]

\rotatebox{30}{
  \begin{minipage}{0.5\textwidth}
     \centering
     \begin{tabular}{|c|c|c|}
        \hline
        1 & 2 & 3\\
        \hline
        4 & 5 & 6\\
        \hline
     \end{tabular}
     \caption{Rotated caption}
  \end{minipage}
}
    
 \end{table}
 
Rotate an image with caption in \LaTeX :\\[4pt]
\begin{figure}[H]
 
\rotatebox{30}{
\begin{minipage}{0.5\textwidth}
        \centering
        \includegraphics[width=.5\textwidth]{CodeSpeedy-Logo.png}
        \caption{Rotated caption}
\end{minipage}
}

\end{figure}

\end{document}

Output:

rotate table and image with caption.

Rotate table or image at 90 degree

If you want to rotate the table or image including the caption at 90-degree angle then you can use the lscape package. This package provides a \begin{landscape} environment to place the table vertically (90 degree).

But in this case, this table will take up a whole page space. There will be no text other than the table on that page.

\documentclass{article}
\usepackage{float} % To fix floating objects
\usepackage{lscape}

\begin{document}

\begin{landscape}
\begin{table}[H]
     \centering
     \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|}
        \hline
        1 & 2 & 3 & 2 & 3 & 2 & 3 & 2 & 3 & 2 & 3\\
        \hline
        4 & 5 & 6 & 5 & 6 & 5 & 6 & 5 & 6 & 5 & 6\\
        \hline
        1 & 2 & 3 & 2 & 3 & 2 & 3 & 2 & 3 & 2 & 3\\
        \hline
        4 & 5 & 6 & 5 & 6 & 5 & 6 & 5 & 6 & 5 & 6\\
        \hline
        1 & 2 & 3 & 2 & 3 & 2 & 3 & 2 & 3 & 2 & 3\\
        \hline
        4 & 5 & 6 & 5 & 6 & 5 & 6 & 5 & 6 & 5 & 6\\
        \hline
        1 & 2 & 3 & 2 & 3 & 2 & 3 & 2 & 3 & 2 & 3\\
        \hline
        4 & 5 & 6 & 5 & 6 & 5 & 6 & 5 & 6 & 5 & 6\\
        \hline
     \end{tabular}
     \caption{Rotated caption}
 \end{table}
 \end{landscape}

\end{document}

Output:

rotate table with caption
But you can’t rotate the image with this process. Don’t worry we have another method. You can do this with the rotating package. This package provides sidewaysfigure environment for figure and sidewaystable for table.

With these environments, you can rotate a figure (image) or table at 90 degrees.

\documentclass{article}
\usepackage{graphicx}
\usepackage{rotating}

\begin{document}

\begin{sidewaysfigure}
    \centering
    \includegraphics[width=0.7\textwidth]{CodeSpeedy-Logo.png}
\caption{Rotated caption}
\end{sidewaysfigure}

\end{document}

Output:

rotate image with caption.

A similar process for the table. In this case, you have to use the sidewaystable environment.

\documentclass{article}
\usepackage{rotating}

\begin{document}

\begin{sidewaystable}
    \centering
    \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|}
        \hline
        1 & 2 & 3 & 2 & 3 & 2 & 3 & 2 & 3 & 2 & 3\\
        \hline
        4 & 5 & 6 & 5 & 6 & 5 & 6 & 5 & 6 & 5 & 6\\
        \hline
        1 & 2 & 3 & 2 & 3 & 2 & 3 & 2 & 3 & 2 & 3\\
        \hline
        4 & 5 & 6 & 5 & 6 & 5 & 6 & 5 & 6 & 5 & 6\\
        \hline
        1 & 2 & 3 & 2 & 3 & 2 & 3 & 2 & 3 & 2 & 3\\
        \hline
        4 & 5 & 6 & 5 & 6 & 5 & 6 & 5 & 6 & 5 & 6\\
        \hline
        1 & 2 & 3 & 2 & 3 & 2 & 3 & 2 & 3 & 2 & 3\\
        \hline
        4 & 5 & 6 & 5 & 6 & 5 & 6 & 5 & 6 & 5 & 6\\
        \hline
     \end{tabular}
\caption{Rotated caption}
\end{sidewaystable}

\end{document}

Output:

rotate table with caption.

 

Leave a Reply

Your email address will not be published. Required fields are marked *