[Tex/LaTex] Change all line width proportionally

linetikz-pgftikz-styles

How do I change all line width proportionally to one another for example by a factor of two?

Here is an MWE to illustrate the problem:

\documentclass[tikz, border = 1cm]{standalone}

%some magic line which changes all the line width by a factor of two

\begin{document}

\begin{tikzpicture}

    \draw[thin]  (0,0) -- ++(2,0);

    \draw        (0,1) -- ++(2,0);

    \draw[thick] (0,2) -- ++(2,0);

\end{tikzpicture}

\end{document}

This is not related to pgfplots – How can I set all the default line widths / thickness values to a certain value? because I dont just want to change one line widths.

The default line width should not be change.

Best Answer

The line widths thin, thick, etc. are defined liked this (taken from here):

\tikzset{
    ultra thin/.style= {line width=0.1pt},
    very thin/.style=  {line width=0.2pt},
    thin/.style=       {line width=0.4pt},
    semithick/.style=  {line width=0.6pt},
    thick/.style=      {line width=0.8pt},
    very thick/.style= {line width=1.2pt},
    ultra thick/.style={line width=1.6pt}
}

So I would suggest to replace this definition with every line widths given as a multiple of some length variable (say \mylinewidth). You can then change the value of \mylinewidth globally or locally, and the lines with these options will adjust their widths.

Example (note the comment below):

\documentclass{article}
\usepackage{tikz}

\newlength\mylinewidth
\setlength\mylinewidth{0.4pt}

\tikzset{
    ultra thin/.style= {line width=0.25\mylinewidth},
    very thin/.style=  {line width=0.5\mylinewidth},
    thin/.style=       {line width=\mylinewidth},
    semithick/.style=  {line width=1.5\mylinewidth},
    thick/.style=      {line width=2\mylinewidth},
    very thick/.style= {line width=3\mylinewidth},
    ultra thick/.style={line width=4\mylinewidth},
    every picture/.style={semithick}
}

\begin{document}

\begin{tikzpicture}
    \draw[very thin]  (0,0) -- ++(2,0);
    \draw        (0,1) -- ++(2,0);
    \draw[very thick] (0,2) -- ++(2,0);
\end{tikzpicture}
\hspace{1cm}
\setlength\mylinewidth{1pt}
\begin{tikzpicture}
    \draw[very thin]  (0,0) -- ++(2,0);
    \draw        (0,1) -- ++(2,0);
    \draw[very thick] (0,2) -- ++(2,0);
\end{tikzpicture}

\end{document}

enter image description here

Note: In this example, I used semithick as the default line width because it appeared visually right to me. You can of course use the standard default which is every picture/.style={thin}.