[Tex/LaTex] Rotate a PGF figure, and being able to center it

horizontal alignmentpdftexrotatingtikz-pgf

I have a figure, created in MS Visio, a PDF figure. I have added text to the figure using qtix. The code is pasted below:

\begin{tikzpicture}[scale=0.30]
\pgftext{\includegraphics{TransformerSubstationFeeding}}

\small

\node at (8,-0.5) {Ground};
\node at (-0.5,-0.5) {Ground};
\node at (-9,-0.5) {Ground};

\node at (14.5,9.1) {Public grid; phase A};
\node at (14.5,8.3) {phase A};
\node at (14.5,7.5) {phase B};
\node at (14.5,6.7) {phase C};

\node at (14.5,2.3) {Railway grid};
\node at (14.5,1.5) {catenary};
\node at (14.5,0.7) {rail/ground};

\node at (11.5,3.8) {Transformer};
\node at (3.0,3.8) {Transformer};
\node at (-5.5,3.8) {Transformer};

\end{tikzpicture}

The figure is more landscape-shaped, so I want to rotate the figure in my document. The figure is attached below.

The problem is I dot now know how to rotate figures that are inserted by the \input command. The \includegraphics command can use rotation, but then each text also need to be rotated. And when doing that, the centering of the image fails. I have tried that too. See the code below:

\begin{tikzpicture}[rotate=90,scale=0.32]
\pgftext{\includegraphics{TransformerSubstationFeeding}}

\small

\node[rotate=90] at (8,-0.5) {Ground};
\node[rotate=90] at (-0.5,-0.5) {Ground};
\node[rotate=90] at (-9,-0.5) {Ground};

\node[rotate=90] at (14.5,9.1) {Public grid; phase A};
\node[rotate=90] at (14.5,8.3) {phase A};
\node[rotate=90] at (14.5,7.5) {phase B};
\node[rotate=90] at (14.5,6.7) {phase C};

\node[rotate=90] at (14.5,2.3) {Railway grid};
\node[rotate=90] at (14.5,1.5) {catenary};
\node[rotate=90] at (14.5,0.7) {rail/ground};

\node[rotate=90] at (11.5,3.8) {Transformer};
\node[rotate=90] at (3.0,3.8) {Transformer};
\node[rotate=90] at (-5.5,3.8) {Transformer};


\end{tikzpicture}

The main document part of my code looks like:

\begin{figure}
    \centering
    \input{Visioritning2.pgf}
    \caption{A simplified illustration of how the three-phase grid commonly feeds the railway when using substation transformers}
    \label{Figure:SimplifiedTransformerSubstation}
\end{figure}

So any suggestions of what I should do? The main problem is:

  • How to both rotate and center a PGF-created PDF-based figure with added explanatory text on it?
  • Is it preferable to to the rotation in PGF-code or is it better to do it in the, or before the \input statement?

Best Answer

You can rotate general material, like your whole picture, using the \rotatebox{<angle>}{<content>} macro from the standard graphicx package (already loaded by TikZ anyway), e.g. try \rotatebox{90}{\input{<filename>}}.

This looks also like a good use-case of standalone. The v1.0 version provides \includestandalone[<options, incl. angle>]{<code file, like your .pgf>}. This also allows you to compile the picture on its own, which is very nice during its creation process.


% Visioritning2.tex
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[scale=0.30]
\pgftext{\includegraphics{TransformerSubstationFeeding}}

\small

\node at (8,-0.5) {Ground};
\node at (-0.5,-0.5) {Ground};
\node at (-9,-0.5) {Ground};

\node at (14.5,9.1) {Public grid; phase A};
\node at (14.5,8.3) {phase A};
\node at (14.5,7.5) {phase B};
\node at (14.5,6.7) {phase C};

\node at (14.5,2.3) {Railway grid};
\node at (14.5,1.5) {catenary};
\node at (14.5,0.7) {rail/ground};

\node at (11.5,3.8) {Transformer};
\node at (3.0,3.8) {Transformer};
\node at (-5.5,3.8) {Transformer};

\end{tikzpicture}
\end{document}

% Main document
\documentclass{article}% or any other
\usepackage{tikz}
\usepackage{standalone}
\begin{document}
% ...
\begin{figure}
    \centering
    \includestandalone[angle=90]{Visioritning2}
    \caption{A simplified illustration of how the three-phase grid commonly feeds the railway when using substation transformers}
    \label{Figure:SimplifiedTransformerSubstation}
\end{figure}
% ...
\end{document}