tikzset 使用时如何在文档中间设置默认样式

tikzset 使用时如何在文档中间设置默认样式

我在 latex 中遇到了一个问题。我必须使用 tikzset 环境来绘制一些图形。但是,绘制完这些图形后,我不再需要 tikzset 环境了。此外,tikzset 使其他图形变得很奇怪。

如何在文档中间设置默认样式?

图1是正确的,但是图2的刻度很奇怪。

    \usepackage[dvipsnames]{xcolor}
    \usepackage{marvosym}
    \usepackage{tikz}
    \usepackage{array}
    \usepackage{pgfplots}

    \usetikzlibrary{arrows}
    \usetikzlibrary{backgrounds}
    \usetikzlibrary{calc}
    \usetikzlibrary{chains}
    \usetikzlibrary{decorations.markings}
    \usetikzlibrary{decorations.pathmorphing}
    \usetikzlibrary{decorations.pathreplacing}
    \usetikzlibrary{fit}
    \usetikzlibrary{intersections}
    \usetikzlibrary{matrix}
    \usetikzlibrary{positioning}
    \usetikzlibrary{shapes.arrows}
    \usetikzlibrary{shapes.geometric}
    \usetikzlibrary{shapes.multipart}
    \usetikzlibrary{shapes.symbols}
    \usetikzlibrary{trees}

    \tikzset{>=latex}

    \tikzset{
      smallfunction/.style={
        rectangle, 
        rounded corners, 
        draw=black, thick,
        minimum height=1.66em, 
        text centered,
      },
      function/.style={
        smallfunction, 
        minimum width=0.8cm,
      },
      cross line/.style={preaction={draw=white, -, shorten >=1pt, shorten <=1pt, line width=3.33pt}},
      arrow/.style = {->,black,semithick},
      connect/.style = {-,semithick},
      decoration={brace},
    }

    \def\branch#1{\fill #1 circle [radius=1.5pt];}

    \tikzset{XOR/.style=
              {draw,circle,thick,fill=white,scale=1.1,append after command={
                [shorten >=\pgflinewidth, shorten <=\pgflinewidth,]
                (\tikzlastnode.north) edge[thick] (\tikzlastnode.south)
                (\tikzlastnode.east) edge[thick] (\tikzlastnode.west)}
              },
             PLUS/.style=
              {draw,rectangle,thick,fill=white,scale=1.5,append after command={
                [shorten >=\pgflinewidth, shorten <=\pgflinewidth,]
                (\tikzlastnode.north) edge[thick] (\tikzlastnode.south)
                (\tikzlastnode.east) edge[thick] (\tikzlastnode.west)}
              },
             branch/.style=
               {fill,shape=circle,minimum size=3pt,inner sep=0pt},
    }

    \begin{document}

    \begin{figure}[h]
        \centering
        \begin{tikzpicture}
        \matrix[column sep={14mm,between origins}, row sep={9mm,between origins}] {
            \node[] (ina2) {$X_{23}\left[0\right]$}; & & \node[] (inb2) {$X_{23}\left[1\right]$}; & & \node[] (inc2) {$X_{23}\left[2\right]$}; & & \node[] (ind2) {$X_{23}\left[3\right]$}; \\
             & & & & & & \node[XOR] (X8) {}; \\
             & & & & \node[branch, blue] (B9) {}; & \node[XOR] (X9) {}; & \node[PLUS] (P9) {}; \\
             & & & & \node[XOR] (X10) {}; & & \node[function] (F10) {$ROR_3$}; \\
             & & \node[branch] (B11) {}; & \node[XOR] (X11) {}; & \node[PLUS] (P11) {}; \\
             & & \node[XOR] (X12) {}; & & \node[function] (F12) {$ROR_5$}; \\
            \node[branch] (B13) {}; & \node[XOR] (X13) {}; & \node[PLUS] (P13) {}; \\
             & & \node[function] (F14) {$ROL_9$}; \\
            \node[coordinate] (outa1) {}; & & \node[coordinate] (outb1) {}; & & \node[coordinate] (outc1) {}; & & \node[coordinate] (outd1) {}; \\[6mm]
            \node[] (ina3) {$X_{24}\left[0\right]$}; & & \node[] (inb3) {$X_{24}\left[1\right]$}; & & \node[] (inc3) {$X_{24}\left[2\right]$}; & & \node[] (ind3) {$X_{24}\left[3\right]$}; \\
        };
        
        \node[blue] at ($(inc2) + (0.7,3mm)$) {\huge{\Lightning}};
        
        % verticals
        \draw[connect] (ina2) -- (B13); \draw[connect] (B13) -- (outa1);
        \draw[connect] (inb2) -- (B11); \draw[arrow] (B11) -- (X12); \draw[arrow] (X12) -- (P13); \draw[arrow] (P13) -- (F14); \draw[connect] (F14) -- (outb1);
        \draw[connect, blue, dashed] (inc2) -- (B9); \draw[arrow, blue, dashed] (B9) -- (X10); \draw[arrow, blue, dashed] (X10) -- (P11); \draw[arrow, blue, dashed] (P11) -- (F12); \draw[connect, blue, dashed] (F12) -- (outc1);
        \draw[arrow] (ind2) -- (X8); \draw[arrow] (X8) -- (P9); \draw[arrow, blue, dashed] (P9) -- (F10); \draw[connect, blue, dashed] (F10) -- (outd1);
        
        % horizontals
        \draw[arrow, blue, dashed] (B9) -- (X9); \draw[arrow, blue, dashed] (X9) -- (P9);
        \draw[arrow] (B11) -- (X11); \draw[arrow] (X11) -- (P11);
        \draw[arrow] (B13) -- (X13); \draw[arrow] (X13) -- (P13);
        
        % extra nodes for key mixing
        \node[left=4.5mm of X8] (RK235) {$RK_{23}\left[5\right]$}; \draw[arrow] (RK235) -- (X8);
        \node[below=4.5mm of X9] (RK234) {$RK_{23}\left[4\right]$}; \draw[arrow] (RK234) -- (X9);
        \node[left=4.5mm of X10] (RK233) {$RK_{23}\left[3\right]$}; \draw[arrow] (RK233) -- (X10);
        \node[below=4.5mm of X11] (RK232) {$RK_{23}\left[2\right]$}; \draw[arrow] (RK232) -- (X11);
        \node[left=4.5mm of X12] (RK231) {$RK_{23}\left[1\right]$}; \draw[arrow] (RK231) -- (X12);
        \node[below=4.5mm of X13] (RK230) {$RK_{23}\left[0\right]$}; \draw[arrow] (RK230) -- (X13);
        
        % exit
        \draw[arrow, rounded corners] (outa1) -- ($(outa1) - (0,3mm)$) -- ($(ind3) + (0,7mm)$) -- (ind3);
        \draw[arrow, cross line, rounded corners] (outb1) -- ($(outb1) - (0,3mm)$) -- ($(ina3) + (0,7mm)$) -- (ina3);
        \draw[arrow, cross line, rounded corners, blue, dashed] (outc1) -- ($(outc1) - (0,3mm)$) -- ($(inb3) + (0,7mm)$) -- (inb3);
        \draw[arrow, cross line, rounded corners, blue, dashed] (outd1) -- ($(outd1) - (0,3mm)$) -- ($(inc3) + (0,7mm)$) -- (inc3);
        
        \end{tikzpicture}
        \caption{The propagation process of a fault injected into the 2-nd input word of the last round, $X_{23}\left[2\right]$, of LEA-128}
        \label{fig:LEA_dfa_step3}
    \end{figure}

    \begin{figure}[h]
        \centering
        \begin{tikzpicture}
        \begin{axis}[
        xlabel = {Number of fault injected ciphertexts},
        ylabel = {Number of revealed bits},
        xmin = 2,
        xmax = 11,
        ymin = 0,
        ymax = 32,
        ytick={0,4,8,12,16,20,24,28,32},
        legend pos = south east,
        ymajorgrids = true,
        axis lines = left,
        ]

        \addplot[
        color=blue,
        thick,
        ]
        coordinates {
        (2,18.1)(3,25.1)(4,27.3)(5,30.1)(6,30.9)(7,31)(8,31)(9,31)(10,31)(11,31)
        };
        \addplot[
        color=red,
        thick,
        dashed
        ]
        coordinates {
        (2,21.6)(3,27.3)(4,29.5)(5,30.6)(6,31)(7,31)(8,31)(9,31)(10,31)(11,31)
        };
        \legend{$A$,$B$}
        
        \end{axis}
        \end{tikzpicture}
        \caption{The number of revealed bits according to the number of fault injected ciphertexts}
        \label{fig:number_of_bits}
    \end{figure}

    \end{document}

相关内容