6

I'm not able to avoid indentation of my tikzpicture inside a resized box.

I've put \noindent everywhere but the figure is still indented.

Maybe it's a stupid mistake but I can't fix it.

\documentclass[11pt,openright]{book}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[british]{babel}
\usepackage{blindtext}
\usepackage{makecell}

\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=3cm,bmargin=3.5cm,lmargin=4cm,rmargin=3cm,marginparwidth=70pt}

\usepackage[margin=10pt,font=small,labelfont=bf,labelsep=period,format=hang,indention=0cm]{caption}

\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{calc, intersections}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{mindmap,trees}
\usetikzlibrary{positioning}
\pgfplotsset{compat=newest}

\begin{document}
\blindtext

\noindent\begin{figure}[!t]
\noindent\resizebox{\textwidth}{!}{%
\tikzset{root concept/.append style={font=\huge}}
\tikzset{level 1 concept/.append style={sibling angle=120, font=\small, minimum size=3cm, level distance=140pt}}
\tikzset{level 2 concept/.append style={sibling angle=60, font=\scriptsize, minimum size=2cm, level distance=100pt}}
\tikzset{level 3 concept/.append style={sibling angle=60, font=\tiny, minimum size=1.3cm, level distance=70pt}}
\tikzset{concept/.append style={fill={none}, text width=}}
\noindent\begin{tikzpicture}
\path[mindmap, concept color=gray!30, text=black]%
    node [concept] {\textbf{Quack}}
    [clockwise from=0]
    child { node [concept] {\makecell*{\textbf{Ducks}\\ \textbf{and ducks}}}
            [clockwise from=60]
            child { node  [concept] {\makecell*{Papere\\ Little ducks}}
                [clockwise from=90]
                child { node [concept] {Paperine}}
                child { node [concept] {Ducks}}
                }
            child { node [concept] {\makecell*{Papere\\ Funny ducks}}
               [clockwise from=30]
                child { node  [concept] {Paperine}}
                child { node [concept] {Ducks}}
                }
            child { node  [concept] {\makecell*{Papere\\ Pretty ducks}}
               [clockwise from=-30]
                child { node [concept] {Paperine}}
                child { node  [concept] {Ducks}}
              }
            }
  child { node [concept] {\makecell*{\textbf{Mallards}\\ \textbf{and mallards}}}}
  child { node [concept] {\makecell{\textbf{Geese}\\ \textbf{and geese}}}}
;
\end{tikzpicture}
}%
\caption{\label{fig:test}Test figure.}
\end{figure}
\end{document}

enter image description here

  • 1
    Sporadic spaces: the space after each \tikzset counts, also the one after \end{tikzpicture} counts in the width \resizebox ends up using. I'd rather recommed learning to scale the image directly than using \resizebox – daleif Sep 22 '16 at 12:54
  • 1
    None of your \noindent command does something sensible; the first one is actually wrong, as it produces a one line (otherwise empty) paragraph. – egreg Sep 22 '16 at 12:54
  • @daleif Thank you! It's sufficient to put a % at the end of the \tikzset lines and all works. I knew that it was a stupid error! I tried to scale the picture without \resizebox but I wasn't able to do that! – CarLaTeX Sep 22 '16 at 13:01
  • @egreg I've put \noindent everywhere just to try to find the solution! – CarLaTeX Sep 22 '16 at 13:04
  • 1
    @CarLaTeX, your missing the one after \end{tikzpicture}, you'll probably not notice until use add the stuff I mention in the comment to Davids answer – daleif Sep 22 '16 at 13:33
6

By default, paragraph indentation is 0pt inside a float so the \noindent inside are doing nothing, the \noindent before the \begin{figure} is completely wrong and will force the creation of a "white" paragraph that looks like vertical space.

The horizontal shift was not due to indentation but to extra space characters added after each of the \tikzset (and there was an additional space at the end of the \resizebox).

Note I left the option as [!t] but this is very restrictive as it does not allow the float to be placed on a float page, so makes it harder for latex to find a good place. It is almost always better to include p or simply not have the option.

\documentclass[11pt,openright]{book}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[british]{babel}
\usepackage{blindtext}
\usepackage{makecell}

\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=3cm,bmargin=3.5cm,lmargin=4cm,rmargin=3cm,marginparwidth=70pt}

\usepackage[margin=10pt,font=small,labelfont=bf,labelsep=period,format=hang,indention=0cm]{caption}

\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{calc, intersections}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{mindmap,trees}
\usetikzlibrary{positioning}
\pgfplotsset{compat=newest}

\begin{document}
\blindtext

%\noindent
\begin{figure}[!t]
%\noindent
\resizebox{\textwidth}{!}{%
\tikzset{root concept/.append style={font=\huge}}%
\tikzset{level 1 concept/.append style={sibling angle=120, font=\small, minimum size=3cm, level distance=140pt}}%
\tikzset{level 2 concept/.append style={sibling angle=60, font=\scriptsize, minimum size=2cm, level distance=100pt}}%
\tikzset{level 3 concept/.append style={sibling angle=60, font=\tiny, minimum size=1.3cm, level distance=70pt}}%
\tikzset{concept/.append style={fill={none}, text width=}}%
%\noindent
\begin{tikzpicture}
\path[mindmap, concept color=gray!30, text=black]%
    node [concept] {\textbf{Quack}}
    [clockwise from=0]
    child { node [concept] {\makecell*{\textbf{Ducks}\\ \textbf{and ducks}}}
            [clockwise from=60]
            child { node  [concept] {\makecell*{Papere\\ Little ducks}}
                [clockwise from=90]
                child { node [concept] {Paperine}}
                child { node [concept] {Ducks}}
                }
            child { node [concept] {\makecell*{Papere\\ Funny ducks}}
               [clockwise from=30]
                child { node  [concept] {Paperine}}
                child { node [concept] {Ducks}}
                }
            child { node  [concept] {\makecell*{Papere\\ Pretty ducks}}
               [clockwise from=-30]
                child { node [concept] {Paperine}}
                child { node  [concept] {Ducks}}
              }
            }
  child { node [concept] {\makecell*{\textbf{Mallards}\\ \textbf{and mallards}}}}
  child { node [concept] {\makecell{\textbf{Geese}\\ \textbf{and geese}}}}
;
\end{tikzpicture}%
}%
\caption{\label{fig:test}Test figure.}
\end{figure}
\end{document}
  • 1
    You missed the one after \end{tikzpicture}, illustrated using showframe package and inserting \draw [blue] (current bounding box.south west) rectangle (current bounding box.north east); into the image – daleif Sep 22 '16 at 13:03
  • 1
    @daleif fixed thanks (sorry hadn't noticed your comment under the question before making an answer:-) – David Carlisle Sep 22 '16 at 13:05
  • I put \noindents everywhere just to try to find the solution, I imagined that some of them were wrong, thank you! – CarLaTeX Sep 22 '16 at 13:07
  • @daleif I'll wait a couple of days before accepting (the very accurate) David's answer. I was thinking (if you have time and will) you could post your own answer, showing how to highlight the error through showframe as you said in the comment and how to scale the image directly with tikz, avoiding \resizebox, I would be very grateful! – CarLaTeX Sep 23 '16 at 6:49
2

This is just a supplement to Davids answer showing how to visualize the issue.

See the two lines marked by % <--, showframe visually shows the size of the text block, that is where the text width is.

The \draw [blue] (current bounding box.south west) rectangle (current bounding box.north east); draws a blue box around the image showing the borders of the image. In our case it shows that the problematic spaces are outside the box, and thus most likely to come from sporadic spaces.

\documentclass[11pt,openright]{book}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[british]{babel}
\usepackage{blindtext}
\usepackage{makecell}

\usepackage{showframe} % <-- added

\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=3cm,bmargin=3.5cm,lmargin=4cm,rmargin=3cm,marginparwidth=70pt}

\usepackage[margin=10pt,font=small,labelfont=bf,labelsep=period,format=hang,indention=0cm]{caption}

\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{calc, intersections}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{mindmap,trees}
\usetikzlibrary{positioning}
\pgfplotsset{compat=newest}

\begin{document}
\blindtext

\noindent\begin{figure}[!t]
\noindent\resizebox{\textwidth}{!}{%
\tikzset{root concept/.append style={font=\huge}}
\tikzset{level 1 concept/.append style={sibling angle=120, font=\small, minimum size=3cm, level distance=140pt}}
\tikzset{level 2 concept/.append style={sibling angle=60, font=\scriptsize, minimum size=2cm, level distance=100pt}}
\tikzset{level 3 concept/.append style={sibling angle=60, font=\tiny, minimum size=1.3cm, level distance=70pt}}
\tikzset{concept/.append style={fill={none}, text width=}}
\noindent\begin{tikzpicture}
\path[mindmap, concept color=gray!30, text=black]%
    node [concept] {\textbf{Quack}}
    [clockwise from=0]
    child { node [concept] {\makecell*{\textbf{Ducks}\\ \textbf{and ducks}}}
            [clockwise from=60]
            child { node  [concept] {\makecell*{Papere\\ Little ducks}}
                [clockwise from=90]
                child { node [concept] {Paperine}}
                child { node [concept] {Ducks}}
                }
            child { node [concept] {\makecell*{Papere\\ Funny ducks}}
               [clockwise from=30]
                child { node  [concept] {Paperine}}
                child { node [concept] {Ducks}}
                }
            child { node  [concept] {\makecell*{Papere\\ Pretty ducks}}
               [clockwise from=-30]
                child { node [concept] {Paperine}}
                child { node  [concept] {Ducks}}
              }
            }
  child { node [concept] {\makecell*{\textbf{Mallards}\\ \textbf{and mallards}}}}
  child { node [concept] {\makecell{\textbf{Geese}\\ \textbf{and geese}}}}
;
\draw [blue] (current bounding box.south west) rectangle (current
bounding box.north east); % <-- added
\end{tikzpicture}
}%
\caption{\label{fig:test}Test figure.}
\end{figure}
 \end{document}

enter image description here

  • +1: I wasn't aware of the showframe package. Very useful! – Daniel Sep 23 '16 at 8:33
  • Thank you very much! As you see, someone else found it useful! As for scaling, unfortunately if I use \centering\begin{tikzpicture}[scale=0.8] or \centering\begin{tikzpicture}[scale=0.8, x=8mm,y=8mm] the links between the nodes are too short, while if I use\centering\begin{tikzpicture}[x=8mm,y=8mm] (or any other value) the image is pagewidth. Maybe I have to work also on node size... – CarLaTeX Sep 23 '16 at 8:39
  • @CarLaTeX that is very strange, mind maps ignore the x=,y= completely. Perhaps they should be scaled in some other manner. I'll remove the comment in the text – daleif Sep 23 '16 at 8:46
  • @CarLaTeX perhaps some of this can be used: tex.stackexchange.com/a/78204/3929 – daleif Sep 23 '16 at 8:49
  • 1
    @daleif Just for info: using the link you suggested to me, I've found the option for scaling mind maps: transform shape. For example \begin{tikzpicture}[scale=1.09, transform shape]. – CarLaTeX Sep 30 '16 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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