3

How do you globally set the default arrow size that Tikz uses when drawing graphical model diagrams?

Reduced example:

\documentclass[13pt]{beamer}
\usetheme{Singapore}
\usepackage{tikz}
\usetikzlibrary{fit,positioning,shapes,arrows,positioning,matrix,shapes.geometric,bayesnet}
\begin{document}
\begin{frame}{test}
\begin{tikzpicture}[]
    \node[obs,circle] (a) {a};
    \node[obs,circle,right=of a] (b) {b};%
    \node[obs,circle,right=of b] (c) {c};%
    \edge {a} {b}; 
    \edge[style={-latex}] {b} {c};
    \end{tikzpicture}
\end{frame}
\end{document}

enter image description here

  • The code can't be littered with adjustments [style={-latex}] for every edge
  • The adjustment should be a single command in the header that affects the default style for all arrows in all tikzpictures
  • I'd like to adjust the size somewhere between the default -> and the smaller -latex (pictured above).

Related questions

This question is very similar (the same?), but I couldn't pull a solution from the answers. The answers discuss how to override the style for single arrows, not how to scale all the default arrowheads by some fixed, global amount.

This one has an answer that is way too fancy for my needs, and it's hard for me to parse out what the simpler answer is from this larger amount of code.

This question probably contains a hint for the answer, but it's for tikz-cd and sets the size of the "latex" arrow head, which isn't the default in Beamer it seems. Tex/Latex/Tikz/etc syntax is arcane enough that I can't guess what changes to this would let me set the default arrow size globally.

This one changes some other arrow properties, but again---the langauge is such that one cannot guess a simplified command to affect the arrow head size.

This one probably contains the answer, but also contains a lot of extra information that is making it hard for me to parse out a simple solution to this specific issue.

From that question, this answer seems the simplest. I can confirm that adding

\usetikzlibrary{arrows.meta}
\tikzset{>={Latex[scale=1.2]}

Does seem to change the default arrow style to Latex and also configure its size.

Which raises the question: what was the default style in Beamer before applying this? Using -> and <-> by default draw a larger arrow than -latex, so it must be something else (in Beamer at least). What is it, and whats the simplest way to configure it?

Is there a way to scale whatever this default arrowhead is, or to all arrowheads? Such that using e.g. \edge[style={<->}] would automatically lead to an arrowhead of the desired size? It looks like this arrows.meta is a package for very fancy arrows, which I don't especially care about. Is there no way to globally adjust the size of the simpler/older arrows package?

3 Answers 3

2

Changing the arrow length: redefine the style latent from bayesnet. (obs is based on latent) Default uses node distance=1.

Or use instead

    \tikzstyle{obs} = [circle,fill=white,draw=black,inner sep=1pt,
    minimum size=20pt, font=\fontsize{10}{10}\selectfont, node distance=0.5,fill=gray!25 ]

To avoid adding the optional parameter[style={-latex}] every time to \edge, you can define a new command.

\newcommand{\edgex}[3][style={-latex}]{% edge with a new style <<<
    % Connect all nodes #2 to all nodes #3.
    \foreach \x in {#2} { %
        \foreach \y in {#3} { %
            \draw[#1] (\x) -- (\y) ;%
        } ;
    } ;
}
    

Putting everything together:

a

\documentclass[13pt]{beamer}
\usetheme{Singapore}
\usepackage{tikz}
\usetikzlibrary{fit,positioning,shapes,positioning,matrix,shapes.geometric,bayesnet}
\usetikzlibrary{arrows.meta}

\newcommand{\edgex}[3][style={-latex}]{% edge with a new style <<<
    % Connect all nodes #2 to all nodes #3.
    \foreach \x in {#2} { %
        \foreach \y in {#3} { %
            \draw[#1] (\x) -- (\y) ;%
        } ;
    } ;
}
    
\begin{document}
\begin{frame}{test}
\begin{tikzpicture}[]
    \node[obs,circle] (a) {a};
    \node[obs,circle,right=of a] (b) {b};%
    \node[obs,circle,right=of b] (c) {c};%
    \edge {a} {b}; 
    \edge[style={-latex}] {b} {c};
\end{tikzpicture}
\bigskip
    
% change distance between nodes
\tikzstyle{obs} = [circle,fill=white,draw=black,inner sep=1pt,minimum size=20pt, font=\fontsize{10}{10}\selectfont, node distance=0.5,fill=gray!25 ]
    
    
\begin{tikzpicture} 
    \node[obs,circle] (a) {a};
    \node[obs,circle,right=of a] (b) {b};%
    \node[obs,circle,right=of b] (c) {c};%
    \edge {a} {b}; 
    \edgex {b} {c};
\end{tikzpicture}
    
\end{frame}
\end{document}
4

It is the (global) setting \tikzset{>={triangle 45}} added by tikz library bayesnet that causes the size difference between arrows -> and -latex. Nothing to do with class beamer.

According to the pgfmanual, sec. 16.4.4 Defining Shorthands, key handler <key>/.tip,

By default, > is a shorthand for To and To is a shorthand for to (an arrow from the old libraries) when arrows.meta is not loaded library. When arrows.meta is loaded, To is redefined to mean the same as Computer Modern Rightarrow.

Hence you can use \tikzset{<->/.tip=To} to restore to the default arrow tip for ->.

The size difference between arrow tips triangle 45 and latex is built-in and can't be configured by arrow options like scale. Those arrow options are only supported by "complete" arrow tips defined in library arrows.meta, with their names with uppercase first letter. For example, scale=1.2 works for -{Latex[scale=1.2]}, but is ignored for -{latex[scale=1.2]}.

Default arrow options can be set by

\tikzset{arrows={[<arrow options>]}}

see pgfmanual sec. 16.4.5 "Scoping of Arrow Keys". but you must load arrows.meta and make sure all your arrow tips are "complete", aka aware of arrow options.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows.meta}

\begin{document}
\begin{tikzpicture}
  \node (a) {a};
  \node[right=of a] (b) {b};
  \node[right=of b] (c) {c};
  
  \path (a) edge[->] (b) 
        (b) edge[-Latex] (c);
\end{tikzpicture}

\tikzset{arrows={[scale=3]}}

\begin{tikzpicture}
  \node (a) {a};
  \node[right=of a] (b) {b};
  \node[right=of b] (c) {c};
  
  \path (a) edge[->] (b) 
        (b) edge[-Latex] (c);
\end{tikzpicture}
\end{document}

enter image description here

2

As a provisional answer, this is almost the same question.. Most of the answers are overkill for this application, but this one seems to result in scaling the default -> and <-> edges:

\usetikzlibrary{arrows.meta}
\tikzset{>={Latex[scale=1.2]} 

It does leave some questions though: Is there a way to do this without using arrows.meta? It looks like -latex, -Latex, and ->, all render with different sizes if \tikzset{>={Latex[scale=1.2] is removed. This tells me that the default arrow (in Beamer?) is not exactly -latex or -Latex? Is the default arrowhead one of -latex or -Latex, but perhaps scaled? If so, where is this set?

So I think these questions are still open:

  • How is the default arrow(head) in Tikz configured?
  • Can the user make global adjustments to it without using arrows.meta?
  • Is there a generic "scale all arrowheads" command?
  • Does Tikz behave slightly differently from within Beamer?

I'll accept any answer clarifying these ( :

1
  • 2
    Hi! Why don't you want to use arrows.meta? This replaces the old arrows, which is deprecated, and if it's deprecated, probably there are reasons (maybe this that you discovered is one of them!).
    – Rmano
    May 30, 2022 at 17:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .