框图文本与普通文本不一致

框图文本与普通文本不一致

如何在区块内写文字,并且文字必须与正常文本一致。内部文字字体大小比正常字体小太多,例如 11pt。

我的消息来源:

\begin{tikzpicture}
    \hspace*{-1.5in}
    \node  at (0,0) [draw,rectangle,minimum height=1.5cm,minimum width=3cm, align=left] (CP1){MA};
    \node  at (5,0) [draw,rectangle,minimum height=1.5cm,minimum width=3cm] (CP2){SC};
    \node  at (10,0) [draw,rectangle,minimum height=1.5cm,minimum width=3cm, align=left] (CP3){DC};
    \node  at (15,0) [draw,rectangle,minimum height=1.5cm,minimum width=3cm, text centered] (CP4){Switch};
    \draw [->, >=latex] (CP1) -- (CP2);
    \draw [->, >=latex] (CP2) -- (CP3);
    \draw [->, >=latex] (CP3) -- (CP4);
    \draw [->, >=latex] (CP4) -- (18.5,0);
    \draw (17.8,0)node[above]{Output};
    \draw [->, >=latex](-3.5,0.5) --(-1.5,0.5);
    \draw (-3,0.5)node[above]{C};
    \draw [->, >=latex](-3.5,-0.5) --(-1.5,-0.5);
    \draw (-2.7,-0.5)node[below]{M1};
\end{tikzpicture} 

答案1

除了 Sigur 的评论外,您的代码仍有改进空间,我冒昧地提出了一些建议,如下所示。基本上,建议移动 (x,y) 绝对坐标方法,而是使用positioningtikzlibrary 和right, above, below = of <reference>技能来放置节点。此外,此建议为每个节点定义一种样式(以文本为中心),以便代码更简洁。

在此处输入图片描述

代码

\documentclass[11pt]{article}
\usepackage[margin=1cm]{geometry}
\usepackage{tikz,xcolor}
\usetikzlibrary{positioning,calc,arrows}

\begin{document}

You can change the font size inside a tikZ node like you do it in normal LaTeX. 

\tikzset{
every node/.style={text centered,draw,minimum height=1.5cm, minimum width=2cm,node distance=30pt}
}
\begin{tikzpicture}
    \node  [coordinate]  at (0,0.5)  (C){\normalsize C};
    \node  [coordinate,below = of C]   (M1){\small M1};
    \node  [right=of C, yshift=-0.5cm] (CP1){\Large MA};
    \node  [right=of CP1] (CP2)   {\small SC};
    \node  [right=of CP2] (CP3)   {\tiny DC};
    \node  [right=of CP3] (CP4)   {Switch};
    \node  [right=of CP4] (Output){\Huge Output};
    \draw [->, >=latex] (CP1) -- (CP2);
    \draw [->, >=latex] (CP2) -- (CP3);
    \draw [->, >=latex] (CP3) -- (CP4);
    \draw [->, >=latex] (CP4) -- (Output);
    \draw [->, >=latex](C)node[draw=none,,above=-0.5cm]{C} -- (C-|CP1.west);
    \draw [->, >=latex](M1)node[draw=none,below=-0.5cm]{M1} --(M1-|CP1.west);
\end{tikzpicture} 

\end{document}

答案2

通常,如果您不指定大小,字体将以正常大小显示(即文档的字体大小)。tikz提供更改字体属性的键font。例如,如果您将

\begin{tikzpicture}[font=\tiny]

除非您稍后覆盖,否则内的字体大小tikzpicture将保持tiny一致。此键的优点是,当我们将其添加到 的选项中时,可以保持内容整洁node

将此font密钥应用到 Jesse 的代码中:

\documentclass[11pt]{article}
\usepackage[margin=1cm]{geometry}
\usepackage{tikz,xcolor}
\usetikzlibrary{positioning,calc,arrows}

\begin{document}

You can change the font size inside a tikZ node like you do it in normal LaTeX.

\tikzset{
every node/.style={text centered,draw,minimum height=1.5cm, minimum width=2cm,node distance=30pt}
}
\begin{tikzpicture}[font=\normalsize]    %% not needed generally
    \node  [coordinate]  at (0,0.5)  (C){C};
    \node  [coordinate,below = of C,font=\small]   (M1){M1};            %% <-- note the options
    \node  [right=of C, yshift=-0.5cm,font=\Large,text=red] (CP1){MA};
    \node  [right=of CP1,font=\small] (CP2)   {SC};
    \node  [right=of CP2,font=\tiny] (CP3)   {DC};
    \node  [right=of CP3] (CP4)   {Switch};
    \node  [right=of CP4,font=\Huge] (Output){Output};
    \draw [->, >=latex] (CP1) -- (CP2);
    \draw [->, >=latex] (CP2) -- (CP3);
    \draw [->, >=latex] (CP3) -- (CP4);
    \draw [->, >=latex] (CP4) -- (Output);
    \draw [->, >=latex](C)node[draw=none,,above=-0.5cm]{C} -- (C-|CP1.west);
    \draw [->, >=latex](M1)node[draw=none,below=-0.5cm]{M1} --(M1-|CP1.west);
\end{tikzpicture}

\end{document}

在此处输入图片描述

同样,有text一个关键点值得注意。详情请参阅pgfmanual

相关内容