Graphics, Figures & TablesDrawn Picture not centered

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
sgu
Posts: 5
Joined: Sun Jun 30, 2013 6:25 am

Drawn Picture not centered

Post by sgu »

Hi all,

the tikzpicture environment seems to fail to center sometimes. The following is such an example.

Code: Select all

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,calc,positioning,shadows,shapes}

\begin{document}
  \begin{figure}[!htb]
    \centering
    \begin{tikzpicture}
      \draw[help lines] (-6.0,-6.0) grid (6.0,6.0);
      \node[align=center, fill=red!20, rounded corners=14pt, minimum height=2cm, minimum width=4cm] (chbox) at (0,0) {A};
      \node[align=center, fill=red!20, rounded corners=14pt, minimum height=2cm, minimum width=4cm] (meshbox) at (-6.0,0) {B};
      \node[align=center, fill=red!20, rounded corners=14pt, minimum height=2cm, minimum width=4cm] (imagebox) at (6.0,0) {C};
    \end{tikzpicture}
    \caption{Figure caption}
    \label{fig:dummy}
  \end{figure}
\end{document}
Any fix? Thanks.
Last edited by localghost on Sun Jun 30, 2013 9:04 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Drawn Picture not centered

Post by localghost »

Very good example. It makes the probable cause comprehensible at first sight and thus it's quite easy to fix it.

The picture itself is simply too wide. You should get a corresponding warning in the log file (*.log). Simply scale it down by the scale option for the tikzpicture environment. The option is described in Section 22.3 of the PGF/TikZ user guide.


Best regards and welcome to the board
Thorsten
sgu
Posts: 5
Joined: Sun Jun 30, 2013 6:25 am

Drawn Picture not centered

Post by sgu »

The scale option seems not to work well with the minimum height and minimum width options.

Code: Select all

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,calc,positioning,shadows,shapes}

\begin{document}
  \begin{figure}[!htb]
    \centering
    \begin{tikzpicture}[scale=0.3]
      \draw[help lines] (-6.0,-6.0) grid (6.0,6.0);
      \node[align=center,fill=red!20,minimum height=2,minimum width=4] (chbox) at (0,0) {A};
      \node[align=center,fill=red!20,minimum height=2,minimum width=4] (meshbox) at (-6.0,0) {B};
      \node[align=center,fill=red!20,minimum height=2,minimum width=4] (imagebox) at (6.0,0) {C};
    \end{tikzpicture}
    \caption{Figure caption}
    \label{fig:dummy}
  \end{figure}
\end{document}
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Drawn Picture not centered

Post by localghost »

Add the transform shape option either as global option to the tikzpicture environment or locally for every single \node. The option is described in Section 16.7 of the PGF/TikZ user guide.
sgu
Posts: 5
Joined: Sun Jun 30, 2013 6:25 am

Re: Drawn Picture not centered

Post by sgu »

That solves the problem, thank you.
PGF has a lot of options and it looks like the PGF/tikz manual have very good examples to demonstrate the capability of the package but doesn't list all the options and all values for a option. And the PGF package has massive source codes. Any recommended way to find out the complete list of the options and all possible values for a given option? Thank you.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Drawn Picture not centered

Post by localghost »

sgu wrote:[…] PGF has a lot of options and it looks like the PGF/tikz manual have very good examples to demonstrate the capability of the package but doesn't list all the options and all values for a option. […] Any recommended way to find out the complete list of the options and all possible values for a given option? […]
Actually the PGF/TikZ user guide lists all available options. How else would you find the right one for a problem? Perhaps you should browse the user guide by topic, not by keyword.
Post Reply