我在 Tikz 中制作了一个流程图,其中对于梯形(输入/输出)框,我使用了以下命令:
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, text width=3cm, draw=black, fill=blue!30]
我认为这里的问题在于text width
参数,因为如果我删除该output
参数,框(见图片)就没问题,但框上的线条input
不够宽。我称该output
梯形如下:
\node (out1) [io, below of=pro3, yshift=-0.5cm, xshift=0.5] {Output result};
导致梯形过宽,远远超出了所要求的最小值 3 厘米。
将命令更改为
\node (out1) [io, below of=pro3, yshift=-0.5cm, xshift=0.5] {Output result\\~};
即,添加换行符和不间断空格可以正确设置梯形的宽度,但现在有一个毫无意义的空行,这使文本不再在框中垂直居中。
如何才能使第二个梯形具有正确的宽度(3厘米),而又不强制在其中留出空线?
麦格维:
\documentclass[twoside]{report}
\usepackage{mathrsfs,amsmath}
%%%%%%%%%% TIKZ OPTIONS %%%%%%%%%%%%%%
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, text width=3cm, draw=black, fill=red!30]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, text width=3cm, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, text width=3cm, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered,draw=black, text width=2cm, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\newcommand{\vect}[1]{\mathbf{#1}}
\newcommand{\matr}[1]{\mathbf{#1}}
\begin{document}
\begin{tikzpicture}
\node (in1) [io] {Input:\\ $dt,nt,nx$ (scalars);\\ $\vect{x},\vect{p}$ (vectors);\\ $\matr{p}$ (data)};
\node (out1) [io, below of=in1, yshift=-0.5cm, xshift=0.5] {Output result};
\end{tikzpicture}
\begin{tikzpicture}
\node (in1) [io] {Input:\\ $dt,nt,nx$ (scalars);\\ $\vect{x},\vect{p}$ (vectors);\\ $\matr{p}$ (data)};
\node (out1) [io, below of=in1, yshift=-0.5cm, xshift=0.5] {Output result\\~};
\end{tikzpicture}
\end{document}
我复制了本教程并尝试使其适应我的需要。
我在 Windows 7 上使用带有 PdfLaTeX 的 TeXStudio 2.12.4。
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (MiKTeX 2.9 64-bit) (preloaded format=pdflatex 2018.3.14)
答案1
只需添加trapezium stretches=true
(并使用\tikzset
而不是\tikzstyle
)。
\documentclass[twoside]{report}
\usepackage{mathrsfs,amsmath}
%%%%%%%%%% TIKZ OPTIONS %%%%%%%%%%%%%%
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\tikzset{startstop/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, text width=3cm, draw=black, fill=red!30},
io/.style={trapezium, trapezium left angle=70, trapezium right angle=110,
minimum width=3cm, minimum height=1cm, text centered, text width=3cm,
draw=black, fill=blue!30,trapezium stretches=true}, %<- added
process/.style={rectangle, minimum width=3cm, minimum height=1cm, text centered, text width=3cm, draw=black, fill=orange!30},
decision/.style={diamond, minimum width=3cm, minimum height=1cm, text
centered,draw=black, text width=2cm, fill=green!30},
arrow/.style={thick,->,>=stealth}}
\newcommand{\vect}[1]{\mathbf{#1}}
\newcommand{\matr}[1]{\mathbf{#1}}
\begin{document}
\begin{tikzpicture}
\node (in1) [io] {Input:\\ $dt,nt,nx$ (scalars);\\ $\vect{x},\vect{p}$ (vectors);\\ $\matr{p}$ (data)};
\node (out1) [io, below of=in1, yshift=-0.5cm, xshift=0.5] {Output result};
\end{tikzpicture}
\begin{tikzpicture}
\node (in1) [io] {Input:\\ $dt,nt,nx$ (scalars);\\ $\vect{x},\vect{p}$ (vectors);\\ $\matr{p}$ (data)};
\node (out1) [io, below of=in1, yshift=-0.5cm, xshift=0.5] {Output result\\~};
\end{tikzpicture}
\end{document}