TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a tikzpicture, rounded by a fbox, and embedded in a minipage. Is it possible to change the position of the whole picture inside the minipage? for instance, move the picture 1 unit higher and 1 unit on the right? I know that we could always change the coordinates of each elements in the picture (e.g., change (2,3) to (1,2)), but it is obviously not a good solution.

share|improve this question
3  
Changing the coordinates wouldn't help anyway, because as far as TeX is concerned for the placement on the page only the bounding box (=outline) of the picture is taken into account. – Caramdir Aug 17 '11 at 1:58
up vote 17 down vote accepted

Horizontal displacement is easily obtained via \hspace[*]{<length>}, while vertical displacement can be managed using \raisebox{<length>}{<stuff>} from the graphicx package. As is clear from the following minimal example, the image on the left has been translated (+3em,+4em), while the duplicate figure on the left has been left unchanged in terms of positioning/translation:

\documentclass{article}
\usepackage{tikz}%
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{caption,subcaption}%
\usepackage{calc}% http://ctan.org/pkg/calc

​\begin{document}
\noindent\begin{minipage}[t]{0.48\linewidth}%
  \centering
  \fbox{%
    \begin{minipage}[t]{\linewidth-2\fboxsep-2\fboxrule}% Remove fbox rule/sep width
      \hspace*{3em}\raisebox{4em}{\begin{tikzpicture}% Moved (+3em,+4em)
        \draw (-1.5,0) -- (1.5,0);
        \draw (0,-1.5) -- (0,1.5);
        \draw (0,0) circle (1cm);
      \end{tikzpicture}}
    \end{minipage}}
  \captionof{figure}{picture1}\label{fig:picture1}
\end{minipage}\hfill
\begin{minipage}[t]{0.48\linewidth}%
  \centering
  \fbox{%
    \begin{minipage}[t]{\linewidth-2\fboxsep-2\fboxrule}% Remove fbox rule/sep width
      \begin{tikzpicture}
        \draw (-1.5,0) -- (1.5,0);
        \draw (0,-1.5) -- (0,1.5);
        \draw (0,0) circle (1cm);
      \end{tikzpicture}
    \end{minipage}}
  \captionof{figure}{picture2}\label{fig:picture2}
\end{minipage}

​\end{document}​​​​​​​​​​​​​

Pictures moved around

share|improve this answer
    
Amazing, that works, thank you again... – SoftTimur Aug 16 '11 at 23:42

As a very late answer, you could do the following to control the spacing above, below and to the left of your tikzpicture (adapting Werner's example):

\fbox{%
  \begin{minipage}[t]{0.8\linewidth}
    \hspace*{0.2\linewidth}
    \rule[-2cm]{0pt}{6cm}
    \begin{tikzpicture}
      \draw (-1.5,0) -- (1.5,0);
      \draw (0,-1.5) -- (0,1.5);
      \draw (0,0) circle (1cm);
    \end{tikzpicture}%
    \begin{tikzpicture}[baseline]
      \draw (-1.5,0) -- (1.5,0);
      \draw (0,-1.5) -- (0,1.5);
      \draw (0,0) circle (1cm);
    \end{tikzpicture}%
    \begin{tikzpicture}[baseline={(0,-0.5)}]
      \draw (-1.5,0) -- (1.5,0);
      \draw (0,-1.5) -- (0,1.5);
      \draw (0,0) circle (1cm);
    \end{tikzpicture}%
  \end{minipage}%
}

The idea is the following:

  • hspace* moves the tikzpicture to the right (as in Werner's response).
  • The invisible rule (or empty width) ensures that the minipage extends (at least) 2cm below the baseline and 4=6-2 cm above the baseline.
  • By default, the tixpicture aligns itself such that the lowest point in the picture is at the baseline.
  • This behaviour can be changed using the baseline option. Simply adding baseline moves the tikzpicture such that the baseline lies at y=0. Otherwise, one may specify a coordinate (but only the y component of this coordinate will play a role).

In this example, the horizontal line through the second circle is precisely at the baseline. output of code

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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