[Tex/LaTex] get a big black line in the document? (Tikzpicture)

tikz-pgf

I do not understand why, but somehow I get a big black line in my pdf, why?

head:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{verbatim}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage[margin=3cm]{geometry}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage[]{mcode}
\usepackage[swedish]{babel}
\usetikzlibrary{calc}
\usepackage{float}
\usepackage{subfig}

\parindent=0pt
\setlength{\parskip}{1em}

\title{Matematisk modellering}
\author{}
\date{February 2016}
\begin{document}

code:

\begin{figure*}[t!]\centering
\begin{tikzpicture}
[
scale=3,
>=stealth,
point/.style = {draw, circle,  fill = black, inner sep = 1pt},
dot/.style   = {draw, circle,  fill = black, inner sep = .2pt},
]
%
% the circle
\draw (0,0) circle (2.12cm);
%
% triangle nodes: just points on the circle
\node (n0) at (0,0) [point, label = below:$S$] {};
\node (n1) at (-1.5,1.5) [point, label = below:$R_{1}$] {};
\node (n2) at (-3,0) [point, label = {below left:$R_{2}$}] {};
\node (n3) at (-2.12,0) [point, label = {below left:$q$}] {};
%
% triangle edges: connect the vertices, and leave a node at the midpoint
\draw[-] (n0) -- node (a) [label = {below left:$\gamma$}] {} (n1);
\draw[-] (n0) -- node (a) [label = {below right:$\gamma$}] {} (n2);
\draw[-] (n2) -- node (a) [label = {below :$vt_{1,2}$}] {} (n3);
\end{tikzpicture}

\end{figure*}

My Circle

Best Answer

First of all, I should point out two things:

  • Package mcode is not available on my computer, which means it either isn't in TeXLive or is in the form of an .ins to be typeset to get a .sty from it, as rmathbr is on CTAN; either way, it is useless, so a good MWE should ideally not include it;
  • Secondly, I compiled the following code:

    \documentclass{article}
    \usepackage[utf8]{inputenc}
    \usepackage{verbatim}
    \usepackage{tikz}
    \usepackage{amsmath}
    \usepackage[margin=3cm]{geometry}
    \usepackage{mathtools}
    \usepackage{graphicx}
    %\usepackage[]{mcode}
    \usepackage[swedish]{babel}
    \usetikzlibrary{calc}
    \usepackage{float}
    \usepackage{subfig}
    
    \parindent=0pt
    \setlength{\parskip}{1em}
    
    \title{Matematisk modellering}
    \author{}
    \date{February 2016}
    \begin{document}
    
    \begin{figure*}[t!]\centering
    \begin{tikzpicture}
    [
    scale=3,
    >=stealth,
    point/.style = {draw, circle,  fill = black, inner sep = 1pt},
    dot/.style   = {draw, circle,  fill = black, inner sep = .2pt},
    ]
    %
    % the circle
    \draw (0,0) circle (2.12cm);
    %
    % triangle nodes: just points on the circle
    \node (n0) at (0,0) [point, label = below:$S$] {};
    \node (n1) at (-1.5,1.5) [point, label = below:$R_{1}$] {};
    \node (n2) at (-3,0) [point, label = {below left:$R_{2}$}] {};
    \node (n3) at (-2.12,0) [point, label = {below left:$q$}] {};
    %
    % triangle edges: connect the vertices, and leave a node at the midpoint
    \draw[-] (n0) -- node (a) [label = {below left:$\gamma$}] {} (n1);
    \draw[-] (n0) -- node (a) [label = {below right:$\gamma$}] {} (n2);
    \draw[-] (n2) -- node (a) [label = {below :$vt_{1,2}$}] {} (n3);
    \end{tikzpicture}
    
    \end{figure*}
    
    \end{document}
    

    to get no overfull rule:

    enter image description here

    So either you have some out-of-date package, or the code you gave does not reproduce your problem.

Assuming you have up-to-date packages, that black line is showing you what the following message tells you:

Overfull \hbox (13.73792pt too wide) in paragraph at lines 45--46

that is, you have a line that's getting out of the page margin, in this case, a huge picture. So you can either:

  • Add the final option to article, i.e. \documentclass[final]{article};
  • Change margin=3cm to e.g. margin=2cm, which removes the overfull;
  • Change scale=3 to e.g. scale=2;
  • Try some \parbox or minipage trickery, though I'm not sure that can widen the margin and remove the overfull; after all, I hardly ever use minipage, and only use \parbox via a macro built for a very specific purpose.

For the record, a very similar question was asked here, and assuming you googled first, you probably didn't find it because of the "edge". Well now we have a nice duplicate target for that question: this one. Flagging soon.

It is strange that you got that. Were you using draft option? Because it should not be default…

Additional remarks

Since you are using LaTeX, you may well want to use the center environment rather than the plain-TeX \centering macro. I do not know if there are any big "upsides" to this choice, but it is generally considered good practice to use LaTeX where you can, and resort to TeX when writing macros where LaTeX is not convenient, unless I'm much mistaken. So I suggest you remove \centering and wrap the figure inside \begin{center}…\end{center}.

This MWE needs neither inputenc, nor verbatim, nor mathtools, nor graphicx, nor mcode, nor babel, so to make it really minimal, you should have removed those packages. They only clutter the code and may make others think one of those is the problem, when the problem is just an overfull box. And I think geometry is also not needed.

In general, before posting, you should check your code reproduces your problem. In this case, it didn't. If the code must be an example of the problem, and it doesn't show the problem, then it's not a good example, right :)?

Update

Turns out I was partly wrong in the part about center. Quoting @barbarabeeton's comment:

the center environment adds extra space above and below; \centering does not. sometimes the environment results in too much space, and in that situation, \centering is not only appropriate, but recommended.