1

I am receiving too much margin for this figure. The figure appear in one full page and I tried \vspace*{-5pt}. Nothing changed. Will be grateful if you help.

\documentclass [12pt] {article}   
\usepackage{hyperref}% http://ctan.org/pkg/hyperref
\renewcommand{\sectionautorefname}{\S}          
\usepackage[cyr]{aeguill}
\usepackage{float}
\usepackage{mathptmx} 
\usepackage[T1]{fontenc}
\usepackage{pgf}
\usepackage{pgfplots}
\usepackage[scaled=2]{helvet}
\usepackage{courier} 
\usepackage{subcaption}
\usepackage{xspace}
\usepackage{fancyhdr}
\usepackage{tkz-tab}
\usepackage{booktabs} 
\usepackage{graphicx}
\usepackage{multirow} 
\usepackage{tabularx}
\usepackage[latin1]{inputenc}
\usepackage{tikz}   
\usetikzlibrary{shapes, arrows, positioning,fit, calc, patterns}
\usepackage{tabularx}   
\usepackage{natbib}
\usepackage[left=3cm, top=3cm, right=3cm, bottom=3cm, nohead]{geometry}
\usepackage{authblk} 
\usepackage{parskip}
\setlength{\parskip}{\medskipamount}
\usepackage{verbatim}
\usepackage{amsmath}
\usepackage[german,english]{babel}   
\newcommand{\minim}{\mathop{\hbox{min}}}
\newcommand{\minimize}[1]{\displaystyle\minim_{#1}}
\newcommand{\st}{\mathop{\hbox{s.t: \thinspace}}} 
\pgfplotsset{compat=1.11}
\usepackage{xcolor}
\renewcommand{\baselinestretch}{1}\normalsize 
\def\firstcircle{(0,0) circle (1.5cm)}
\def\secondcircle{(0:2cm) circle (1.5cm)}
\def\thirdcircle{(0:4cm) circle (1.5cm)}
\def\fourthcircle{(-1.8cm:0.9cm) circle (0.5cm)}
\def\fifthcircle{(0,0) circle (1.5cm)}
\def\sixthcircle{(0:4.5cm) circle (1.5cm)}

\tikzset{filled/.style={fill=white, draw=circle edge, thick},
outline/.style={draw=black, thick}}

\begin{document}  
\begin{figure}[htbp]
\resizebox{0.5\textwidth}{!}{
\begin{tikzpicture} 
\node[shape=circle,draw=black]  (n1) at (1,10) {};
\node[shape=circle,draw=black]  (n2) at (5,10)  {};
\node[shape=circle,draw=black]  (n5) at (1,6)  {};
\node[shape=circle,draw=black]  (n4) at (5,6) {};
\node[shape=circle,draw=black]  (n3) at (10,8)  {};
\node[shape=circle,draw=red,thick]  (n7) at (2,8.5) {$F_1$};
\node[shape=circle,draw=red,thick]  (n8) at (3.5,7) {$F_2$};
\node[shape=circle,draw=red,thick]  (n9) at (7,8) {$F_3$};
\node[shape=circle,draw=red,thick]  (n10) at (3.5,4.5) {$F_4$};
\draw (n1) -- (n2);
\draw (n2) -- (n3);
\draw (n2) -- (n4);
\draw (n2) -- (n5);
\draw (n3) -- (n4);
\draw (n4) -- (n5);
\draw (n5) -- (n1);
\end{tikzpicture}
}
\caption{Graph $G$ as an (isolated) system}
\end{figure}

\begin{figure}[htbp]
\resizebox{0.8\textwidth}{!}{
\begin{tikzpicture}
\node[shape=circle,draw=black]  (n1) at (1,10) {1};
\node[shape=circle,draw=black]  (n2) at (5,10)  {2};
\node[shape=circle,draw=black]  (n5) at (1,6)  {5};
\node[shape=circle,draw=black]  (n4) at (5,6) {4};
\node[shape=circle,draw=black]  (n3) at (10,8)  {3};
\node[shape=circle,draw=red,thick]  (n7) at (2,8.5) {$F_1$};
\node[shape=circle,draw=red,thick]  (n8) at (3.5,7) {$F_2$};
\node[shape=circle,draw=red,thick]  (n9) at (7,8) {$F_3$};
\node[shape=circle,draw=red,thick]  (n10) at (3.5,4.5) {$F_4$};
\draw (n1) -- (n2);
\draw (n2) -- (n3);
\draw (n2) -- (n4);
\draw (n2) -- (n5);
\draw (n3) -- (n4);
\draw (n4) -- (n5);
\draw (n5) -- (n1);
\draw[draw=red, dashed, thick] (n7) -- (n8);
\draw[draw=red, dashed, thick] (n8) -- (n9);
\draw[draw=red, dashed, thick] (n8) -- (n10);
\draw[draw=red, dashed, thick] (n10) to [out=10,in=10] (n9);
\draw[draw=red, dashed, thick] (n7) to [out=-198,in=190,looseness=2] (n10);
\draw[draw=red, dashed, thick] (n10) to [out=-30,in=30,looseness=4] (n9);
\draw[draw=red, dashed, thick] (n7) to [out=100,in=200,looseness=3.5] (n10);
\end{tikzpicture}
}
\caption{Graph $G^\star=(N^\star,A^\star)$}
\end{figure}
\end{document}
  • Welcome! Could you edit your post so that it provides code which we can copy, paste and compile to reproduce the problem? And could you explain what you mean by it has 'too much margin'? Unless you've changed the margins for the current page or part of your document, the margins are presumably what they usually are. – cfr May 7 '17 at 1:25
  • Thanks. I just edited. Two figures are coded: one with regular margins; the second one with two much margins in all directions. – graphlover May 7 '17 at 1:40
  • The M in MWE stands for minimal. – JPi May 7 '17 at 1:43
  • We'd like both minimal and working, if possible, actually. So \end{document} should be there somewhere. – cfr May 7 '17 at 1:54
  • Off-topic: hyperref needs to be loaded last with the exception of certain special packages, most notably cleveref. It won't work properly if loaded first. – cfr May 7 '17 at 1:56
2

Here's a somewhat trimmed document, with \fboxes to show why your figures are placed as they are.

\documentclass [12pt] {article}
\usepackage{float}
\usepackage{mathptmx}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}
% these will look horrible with CM or CM-like fonts
% \usepackage[scaled=2]{helvet}
% \usepackage{courier}
\usepackage{subcaption}
\usepackage{xspace}
\usepackage{fancyhdr}
\usepackage{tkz-tab}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{tabularx}% don't load packages twice
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes, arrows, positioning,fit, calc, patterns}% shapes and arrows are deprecated
\usepackage{natbib}
\usepackage[left=3cm, top=3cm, right=3cm, bottom=3cm, nohead]{geometry}% so fancyhdr is only for footers? no headers in this document?
\usepackage{authblk}
\usepackage{parskip}
\setlength{\parskip}{\medskipamount}
\usepackage{verbatim}
\usepackage{amsmath}
\usepackage[german,english]{babel}
\pgfplotsset{compat=1.11}
\usepackage{hyperref}% http://ctan.org/pkg/hyperref
\renewcommand{\baselinestretch}{1}\normalsize % this is a terrible idea - at least use setspace, but this is too little anyway
\renewcommand{\sectionautorefname}{\S}
\newcommand{\minim}{\mathop{\hbox{min}}}
\newcommand{\minimize}[1]{\displaystyle\minim_{#1}}
\newcommand{\st}{\mathop{\hbox{s.t: \thinspace}}}
\newcommand*\firstcircle{(0,0) circle (1.5cm)}
\newcommand*\secondcircle{(0:2cm) circle (1.5cm)}
\newcommand*\thirdcircle{(0:4cm) circle (1.5cm)}
\newcommand*\fourthcircle{(-1.8cm:0.9cm) circle (0.5cm)}
\newcommand*\fifthcircle{(0,0) circle (1.5cm)}
\newcommand*\sixthcircle{(0:4.5cm) circle (1.5cm)}

\tikzset{filled/.style={fill=white, draw=circle edge, thick},
outline/.style={draw=black, thick}}

\begin{document}
\begin{figure}[htbp]
  \fbox{%
    \resizebox{0.5\textwidth}{!}{% this method is considered evil
      \begin{tikzpicture}
        \node[shape=circle,draw=black]  (n1) at (1,10) {};
        \node[shape=circle,draw=black]  (n2) at (5,10)  {};
        \node[shape=circle,draw=black]  (n5) at (1,6)  {};
        \node[shape=circle,draw=black]  (n4) at (5,6) {};
        \node[shape=circle,draw=black]  (n3) at (10,8)  {};
        \node[shape=circle,draw=red,thick]  (n7) at (2,8.5) {$F_1$};
        \node[shape=circle,draw=red,thick]  (n8) at (3.5,7) {$F_2$};
        \node[shape=circle,draw=red,thick]  (n9) at (7,8) {$F_3$};
        \node[shape=circle,draw=red,thick]  (n10) at (3.5,4.5) {$F_4$};
        \draw (n1) -- (n2);
        \draw (n2) -- (n3);
        \draw (n2) -- (n4);
        \draw (n2) -- (n5);
        \draw (n3) -- (n4);
        \draw (n4) -- (n5);
        \draw (n5) -- (n1);
      \end{tikzpicture}%
    }%
  }
  \caption{Graph $G$ as an (isolated) system}
\end{figure}

\begin{figure}[htbp]
  \fbox{%
    \resizebox{0.8\textwidth}{!}{% this method is considered evil
      \begin{tikzpicture}
        \node[shape=circle,draw=black]  (n1) at (1,10) {1};
        \node[shape=circle,draw=black]  (n2) at (5,10)  {2};
        \node[shape=circle,draw=black]  (n5) at (1,6)  {5};
        \node[shape=circle,draw=black]  (n4) at (5,6) {4};
        \node[shape=circle,draw=black]  (n3) at (10,8)  {3};
        \node[shape=circle,draw=red,thick]  (n7) at (2,8.5) {$F_1$};
        \node[shape=circle,draw=red,thick]  (n8) at (3.5,7) {$F_2$};
        \node[shape=circle,draw=red,thick]  (n9) at (7,8) {$F_3$};
        \node[shape=circle,draw=red,thick]  (n10) at (3.5,4.5) {$F_4$};
        \draw (n1) -- (n2);
        \draw (n2) -- (n3);
        \draw (n2) -- (n4);
        \draw (n2) -- (n5);
        \draw (n3) -- (n4);
        \draw (n4) -- (n5);
        \draw (n5) -- (n1);
        \draw[draw=red, dashed, thick] (n7) -- (n8);
        \draw[draw=red, dashed, thick] (n8) -- (n9);
        \draw[draw=red, dashed, thick] (n8) -- (n10);
        \draw[draw=red, dashed, thick] (n10) to [out=10,in=10] (n9);
        \draw[draw=red, dashed, thick] (n7) to [out=-198,in=190,looseness=2] (n10);
        \draw[draw=red, dashed, thick] (n10) to [out=-30,in=30,looseness=4] (n9);
        \draw[draw=red, dashed, thick] (n7) to [out=100,in=200,looseness=3.5] (n10);
      \end{tikzpicture}%
    }%
  }
  \caption{Graph $G^\star=(N^\star,A^\star)$}
\end{figure}
\end{document}

figures in boxes

The second figure is simply too big for LaTeX to place it at the top or bottom (or 'here'), given its algorithm for float placement. So, it moves it to a float page and, since it is the only float to end up there, it is on a page of its own.

The margins are untouched. This is just how floats work.

A more minimal version:

\documentclass [12pt] {article}
\usepackage{tikz}
\usepackage[left=3cm, top=3cm, right=3cm, bottom=3cm, nohead]{geometry}% so fancyhdr is only for footers? no headers in this document?
\begin{document}
\begin{figure}[htbp]
  \fbox{%
    \resizebox{0.5\textwidth}{!}{% this method is considered evil
      \begin{tikzpicture}
        \node[shape=circle,draw=black]  (n1) at (1,10) {};
        \node[shape=circle,draw=black]  (n2) at (5,10)  {};
        \node[shape=circle,draw=black]  (n5) at (1,6)  {};
        \node[shape=circle,draw=black]  (n4) at (5,6) {};
        \node[shape=circle,draw=black]  (n3) at (10,8)  {};
        \node[shape=circle,draw=red,thick]  (n7) at (2,8.5) {$F_1$};
        \node[shape=circle,draw=red,thick]  (n8) at (3.5,7) {$F_2$};
        \node[shape=circle,draw=red,thick]  (n9) at (7,8) {$F_3$};
        \node[shape=circle,draw=red,thick]  (n10) at (3.5,4.5) {$F_4$};
        \draw (n1) -- (n2);
        \draw (n2) -- (n3);
        \draw (n2) -- (n4);
        \draw (n2) -- (n5);
        \draw (n3) -- (n4);
        \draw (n4) -- (n5);
        \draw (n5) -- (n1);
      \end{tikzpicture}%
    }%
  }
  \caption{Graph $G$ as an (isolated) system}
\end{figure}

\begin{figure}[htbp]
  \fbox{%
    \resizebox{0.8\textwidth}{!}{% this method is considered evil
      \begin{tikzpicture}
        \node[shape=circle,draw=black]  (n1) at (1,10) {1};
        \node[shape=circle,draw=black]  (n2) at (5,10)  {2};
        \node[shape=circle,draw=black]  (n5) at (1,6)  {5};
        \node[shape=circle,draw=black]  (n4) at (5,6) {4};
        \node[shape=circle,draw=black]  (n3) at (10,8)  {3};
        \node[shape=circle,draw=red,thick]  (n7) at (2,8.5) {$F_1$};
        \node[shape=circle,draw=red,thick]  (n8) at (3.5,7) {$F_2$};
        \node[shape=circle,draw=red,thick]  (n9) at (7,8) {$F_3$};
        \node[shape=circle,draw=red,thick]  (n10) at (3.5,4.5) {$F_4$};
        \draw (n1) -- (n2);
        \draw (n2) -- (n3);
        \draw (n2) -- (n4);
        \draw (n2) -- (n5);
        \draw (n3) -- (n4);
        \draw (n4) -- (n5);
        \draw (n5) -- (n1);
        \draw[draw=red, dashed, thick] (n7) -- (n8);
        \draw[draw=red, dashed, thick] (n8) -- (n9);
        \draw[draw=red, dashed, thick] (n8) -- (n10);
        \draw[draw=red, dashed, thick] (n10) to [out=10,in=10] (n9);
        \draw[draw=red, dashed, thick] (n7) to [out=-198,in=190,looseness=2] (n10);
        \draw[draw=red, dashed, thick] (n10) to [out=-30,in=30,looseness=4] (n9);
        \draw[draw=red, dashed, thick] (n7) to [out=100,in=200,looseness=3.5] (n10);
      \end{tikzpicture}%
    }%
  }
  \caption{Graph $G^\star=(N^\star,A^\star)$}
\end{figure}
\end{document}

This produces essentially the same output.

If you wish to change the image's bounding box, then there are various ways to do it. Probably the easiest in this case is to tell PGF not to count the curves and then add a few extra coordinates to expand the bounding box later.

For example,

\documentclass [12pt] {article}
\usepackage{tikz}
\usepackage[left=3cm, top=3cm, right=3cm, bottom=3cm, nohead]{geometry}% so fancyhdr is only for footers? no headers in this document?
\begin{document}
\begin{figure}[htbp]
  \centering
  \resizebox{0.5\textwidth}{!}{% this method is considered evil
    \begin{tikzpicture}
      \node[shape=circle,draw=black]  (n1) at (1,10) {};
      \node[shape=circle,draw=black]  (n2) at (5,10)  {};
      \node[shape=circle,draw=black]  (n5) at (1,6)  {};
      \node[shape=circle,draw=black]  (n4) at (5,6) {};
      \node[shape=circle,draw=black]  (n3) at (10,8)  {};
      \node[shape=circle,draw=red,thick]  (n7) at (2,8.5) {$F_1$};
      \node[shape=circle,draw=red,thick]  (n8) at (3.5,7) {$F_2$};
      \node[shape=circle,draw=red,thick]  (n9) at (7,8) {$F_3$};
      \node[shape=circle,draw=red,thick]  (n10) at (3.5,4.5) {$F_4$};
      \draw (n1) -- (n2);
      \draw (n2) -- (n3);
      \draw (n2) -- (n4);
      \draw (n2) -- (n5);
      \draw (n3) -- (n4);
      \draw (n4) -- (n5);
      \draw (n5) -- (n1);
    \end{tikzpicture}%
  }
  \caption{Graph $G$ as an (isolated) system}
\end{figure}

\begin{figure}[htbp]
  \centering
  \resizebox{0.8\textwidth}{!}{% this method is considered evil
    \begin{tikzpicture}
      \node[shape=circle,draw=black]  (n1) at (1,10) {1};
      \node[shape=circle,draw=black]  (n2) at (5,10)  {2};
      \node[shape=circle,draw=black]  (n5) at (1,6)  {5};
      \node[shape=circle,draw=black]  (n4) at (5,6) {4};
      \node[shape=circle,draw=black]  (n3) at (10,8)  {3};
      \node[shape=circle,draw=red,thick]  (n7) at (2,8.5) {$F_1$};
      \node[shape=circle,draw=red,thick]  (n8) at (3.5,7) {$F_2$};
      \node[shape=circle,draw=red,thick]  (n9) at (7,8) {$F_3$};
      \node[shape=circle,draw=red,thick]  (n10) at (3.5,4.5) {$F_4$};
      \draw (n1) -- (n2);
      \draw (n2) -- (n3);
      \draw (n2) -- (n4);
      \draw (n2) -- (n5);
      \draw (n3) -- (n4);
      \draw (n4) -- (n5);
      \draw (n5) -- (n1);
      \draw[draw=red, dashed, thick] (n7) -- (n8);
      \draw[draw=red, dashed, thick] (n8) -- (n9);
      \draw[draw=red, dashed, thick] (n8) -- (n10);
      \begin{pgfinterruptboundingbox}
        \draw[draw=red, dashed, thick] (n10) to [out=10,in=10] (n9);
        \draw[draw=red, dashed, thick] (n7) to [out=-198,in=190,looseness=2]coordinate [pos=.5] (c3) (n10);
        \draw[draw=red, dashed, thick] (n10) to [out=-30,in=30,looseness=4] coordinate [pos=.2] (c1)  coordinate [pos=.7] (c2)  (n9);
        \draw[draw=red, dashed, thick] (n7) to [out=100,in=200,looseness=3.5] coordinate [pos=.2] (c4) (n10);
      \end{pgfinterruptboundingbox}
      \path (c1) (c2) (c3) (c4);
    \end{tikzpicture}%
  }
  \caption{Graph $G^\star=(N^\star,A^\star)$}
\end{figure}
\end{document}

images with an adjusted bounding box for the second

  • This is great. Thanks a lot for the wonderful help :) – graphlover May 7 '17 at 2:59

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.