51

How can I rotate both a picture and its title in TeX?

Parameter in \includegraphics allows to rotate only a picture.

Werner
  • 603,163
klm123
  • 1,615

5 Answers5

31

This can be done using the adjustbox package. The solution is similar to the one of Werner but saves you some manual work with saveboxes. Note that adjustbox v1.0 also includes a figure key which allows to add the figure environment automatically as well.

\documentclass{article}
\usepackage{adjustbox}
\usepackage{blindtext}
\begin{document}
\blindtext

\begin{figure}[ht]
  \begin{adjustbox}{addcode={\begin{minipage}{\width}}{\caption{%
      Here is a caption of the figure which is so long that 
      it has to be wrapped over multiple lines, but should 
      not exceed the width (height after the rotation) of the image.
      }\end{minipage}},rotate=90,center}
      \includegraphics[scale=.6]{example-image}%
  \end{adjustbox}
\end{figure}

\blindtext
\end{document}

Result

Martin Scharrer
  • 262,582
  • 2
    Is it possible to rotate by 90 or 270 deg depending on whether the page is even or odd? – D.Roepo Oct 12 '13 at 14:10
  • Worth noticing is that it is often recommended to always rotate all pictures in the same direction so that the reader only have to read the book in two direction and not in three, i.e. always have to turn the whole book in the same direction. I am pretty sure Bringhurst recommends this for example. – jonalv Jan 10 '14 at 15:06
  • @jonalv: Yes, I also know it to rotate them so that the lower side is on the right. – Martin Scharrer Jan 13 '14 at 20:42
  • Can you suggest where to out \label? I tried all possibilities but hopeless. – CKM Jul 18 '16 at 10:08
  • @chandresh: Try it inside \caption at the very end just before the }. – Martin Scharrer Jul 19 '16 at 18:55
  • For some reasons this would not completely work for me with the packages I had loaded. The caption was not rotated. The solution posted by @Chogg worked for me though. – basseur May 18 '18 at 20:49
  • Saved my day! Thanks Martin. – Masud Rahman Jun 25 '19 at 18:00
30

The rotating package and sidewaysfigure environment can rotate the figure and caption as you ask. The figure will be placed on a separate page.

The method is described here.

A minimum working example is

\documentclass{article}

\usepackage{rotating}
\usepackage{graphicx}

\begin{document}

\begin{sidewaysfigure}
\includegraphics[width=\columnwidth]{file}%
\label{fig:fig1}
\end{sidewaysfigure}

\end{document}
Chogg
  • 964
12

Here is an elementary way of accomplishing a rotation. It requires boxing the figure contents (via a minipage) before rotating it.

enter image description here

\documentclass{article}
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\newsavebox{\myimage}
\begin{document}
\lipsum[1]
\begin{figure}[ht]
  \centering
  \savebox{\myimage}{\rule{100pt}{150pt}}% Image to be included
  \rotatebox{90}{% Rotate 90 CCW
    \begin{minipage}{\wd\myimage}
      \usebox{\myimage}
      \caption{Here is a caption of the figure.}
    \end{minipage}}
\end{figure}
\end{document}

The image is saved in a box \myimage in order to obtain its width (\wd\myimage). This is then used to set the width of the minipage. I used a dummy 100pt x 150pt black rectangle.

lipsum was used to generate dummy text, Lorem Ipsum style.

Werner
  • 603,163
10

run texdoc hvfloat for the documentation of the different keywords

\documentclass{article}    
\usepackage{hvfloat,lipsum}
\begin{document}

\lipsum[2]
\hvFloat[
 floatPos=!htb,
 capWidth=h,
 capPos=r,
 capAngle=90,
 objectAngle=90,
 capVPos=c,
 objectPos=c]{figure}{\includegraphics[width=4cm]{tiger}}%
{Caption vertically centered right beside the float with a caption
width of figure width and 
\texttt{floatcapsep=5pt} (the default)}{fig:label}

\listoffigures    
\end{document}

enter image description here

4

Simply put angle=X in the \includegraphics command. For example

 \begin{figure}[!h]
    \centering 
    \includegraphics[width=1\textwidth, angle=90]{fig.eps}
    \caption{The caption}
    \label{cap}
\end{figure}   
mahmood
  • 3,359
  • 13
    This is not a good answer because it rotates only the figure and NOT the caption. The question specifically asked for a solution to rotating BOTH figure and caption and notes that your solution rotates only the image. "Parameter in \includegraphics allows to rotate only a picture." – kabZX May 08 '16 at 08:04