使用 tikz 的线/箭头

使用 tikz 的线/箭头

我遇到了一个问题,我认为这个问题可能很容易解决,但我却无法解决。我正在用 Latex 画一个图表,需要用一个圆圈连接不同的矩形。问题是我不知道如何“告诉 Latex”线条和线条末端应该具有相同的颜色。我最终得到了我想要的图形,但问题是箭头是黑色的,而不是我定义的线条颜色。

这是我的代码:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\definecolor{lc_blue}{RGB}{5,110,130}
\definecolor{lc_grey}{RGB}{160,170,160}
\tikzstyle{line} = [draw=lc_blue, -latex', line width=1mm]
\begin{figure}
\centering 
\begin{tikzpicture}
   [place/.style={circle,draw=lc_blue,fill=lc_grey,thick,
inner sep=0pt,minimum size=35mm,text width=1cm},
transition/.style={rectangle, rounded corners, draw=lc_blue,fill=lc_grey,thick,
inner sep=0pt,minimum size=25mm,minimum height=1cm}]
     \node (inc)  at ( 0,-4) [transition] {};
     \node (dial) at ( 0,4)  [transition] {};
     \node (lic)  at ( 0,0)  [place] {};
     \node (conf) at ( 4,0)  [transition] {};
     \node (cred) at (-4,0)  [transition] {};

     \node [black] at (inc)  {\textbf{Inclusión}};
     \node [black] at (dial) {\textbf{Diálogo}};
     \node [black] at (conf) {\textbf{Confianza}};
     \node [black] at (cred) {\textbf{Credibilidad}};
     \node [black] at (lic)  {\textbf{Legitimidad social}}; 
     \path [line] (cred.east) --  (lic.west);
     \path [line] (dial.south) -- (lic.north);
     \path [line] (conf.west) --  (lic.east);
     \path [line] (inc.north) --  (lic.south);
\end{tikzpicture}
\end{figure}
\end{document}

答案1

我猜你现在正在运行 pgfversion 2.10。

您有 3 个选项可以修复此问题:

  1. 将 更改draw=lc_bluecolor=lc_blue

    \tikzstyle{line} = [color=lc_blue,-latex', line width=1mm]
    
  2. 将 更改draw=lc_bluedraw=lc_blue, fill=lc_blue

    \tikzstyle{line} = [draw=lc_blue, fill=lc_blue,-latex', line width=1mm]
    
  3. 将 TikZ 升级到 3.0.1

选项 3 的一个示例。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}

\begin{document}
\definecolor{lc_blue}{RGB}{255,110,130}
\definecolor{lc_grey}{RGB}{160,255,160}
\tikzstyle{line} = [draw=lc_blue, -latex', line width=1mm]

\begin{tikzpicture}
   [place/.style={circle,draw=lc_blue,fill=lc_grey,thick,
inner sep=0pt,minimum size=35mm,text width=1cm},
transition/.style={rectangle, rounded corners, draw=lc_blue,fill=lc_grey,thick,
inner sep=0pt,minimum size=25mm,minimum height=1cm}]
     \node (inc)  at ( 0,-4) [transition] {};
     \node (dial) at ( 0,4)  [transition] {};
     \node (lic)  at ( 0,0)  [place] {};
     \node (conf) at ( 4,0)  [transition] {};
     \node (cred) at (-4,0)  [transition] {};

     \node [black] at (inc)  {\textbf{Inclusión}};
     \node [black] at (dial) {\textbf{Diálogo}};
     \node [black] at (conf) {\textbf{Confianza}};
     \node [black] at (cred) {\textbf{Credibilidad}};
     \node [black] at (lic)  {\textbf{Legitimidad social}}; 
     \path [line] (cred.east) --  (lic.west);
     \path [line] (dial.south) -- (lic.north);
     \path [line] (conf.west) --  (lic.east);
     \path [line] (inc.north) --  (lic.south);
     \node at (-4,4) {pgfversion:\pgfversion};
\end{tikzpicture}
\end{document}

输出:

在此处输入图片描述

答案2

为了使线条和箭头的颜色相同,您需要定义:

\path[line width=1mm, -latex', draw=lc_blue,fill=lc_blue]

或简称:

\path[line width=1mm, -latex', lc_blue]

我将抓住机会将代码重写为更简短的形式。为此,我添加了包positioning

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

    \begin{document}
\definecolor{lc_blue}{RGB}{5,110,130}
\definecolor{lc_grey}{RGB}{160,170,160}
    \begin{figure}
\centering
    \begin{tikzpicture}[
    node distance = 21mm and 13mm,
     place/.style = {circle, draw=lc_blue, fill=lc_grey, thick,
                     inner sep=2mm, text width=24mm, align=center},
transition/.style = {rectangle, rounded corners, draw=lc_blue, thick,
                     fill=lc_grey, inner sep=2mm,
                     minimum size=24mm, minimum height=1cm},
             font = \bfseries]
\node (inc)  [transition]               {Inclusión};
\node (lic)  [place,above=of inc]       {Legitimidad social};
\node (dial) [transition,above=of lic]  {Diálogo};
\node (conf) [transition,right=of lic]  {Confianza};
\node (cred) [transition,left =of lic]  {Credibilidad};
%
\path[line width=1mm, -latex', draw=lc_blue,fill=lc_blue] 
    (cred) edge (lic)   (dial) edge (lic)
    (conf) edge (lic)   (inc)  edge (lic);
    \end{tikzpicture}
\end{figure}
    \end{document}

它给出了略有不同的图像(我缩小了圆圈的尺寸并在其中写了两行文字,但您可以轻松地将其更改为原始设计):

在此处输入图片描述

相关内容