5

If I want to change all edge properties (to e.g. rounded edges instead of mitered edges) in a tikz picture (picture globally), I can do so as follows:

\begin{tikzpicture}[line join=round]

This works fine. However, when attempting to do so for the entire document (globally) using tikzset in the preamble (which seemed a logical step after reading this):

\tikzset{line join=round}

It does not work, although no error appears, and every tikz image uses the default setting (which is miter) unless otherwise specified locally or picture globally.

Does anyone know how to set this property (and the line cap and miter limit property) globally?

EDIT: as requested a small example:

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.8}
\tikzset{line join=round} % <-- This does not have any effect

\begin{document}

% Edges are not affected, as they are still 'mitered':
\begin{tikzpicture}
\begin{axis}
\addplot[color=black,line width=10pt] coordinates
{(0, 0) (1, 1) (2, 0) (3, 1) (4, 0)};
\end{axis}
\end{tikzpicture}

% This is how it's supposed to look like:
\begin{tikzpicture}[line join=round] % (!)
\begin{axis}
\addplot[color=black,line width=10pt] coordinates
{(0, 0) (1, 1) (2, 0) (3, 1) (4, 0)};
\end{axis}
\end{tikzpicture}

\end{document}
JJM Driessen
  • 1,353

1 Answers1

4

You can use the every picture style:

\documentclass{article}
\usepackage{tikz}

\tikzset{
  every picture/.append style={
    line join=round,
    line cap=round,
  }
}

\begin{document}

\begin{tikzpicture}[line width=10pt]
\draw (0,0) -- (0,3) -- (3,0);
\end{tikzpicture}

\end{document}

enter image description here

As for the miter limit, if you try something like

\tikzset{
  every picture/.append style={
    line join=round,
    line cap=round,
    miter limit=25
  }
}

you'll see the option has no real effect since the line join is selected as round for which miter limit doesn't apply. Define a style with line join=miter and an optional parameter for miter limit:

\documentclass{article}
\usepackage{tikz}

\tikzset{
  mystyle/.style={
    line join=miter,
    miter limit=#1
  },
  mystyle/.default=0 
}

\begin{document}

\begin{tikzpicture}[line width=10pt]
\draw[mystyle] (0,0) -- ++(5,0.5) -- ++(-5,0.5);
\draw[miter limit=25] (5,0) -- ++(5,0.5) -- ++(-5,0.5);
\end{tikzpicture}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128