I would like to set the width for a node, in particular, an Input/Output node in Tikz.
\documentclass{article}
\usepackage[utf8]{inputenc}
\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,
draw=black, fill=blue!30]
\begin{document}
\begin{tikzpicture}[node distance=2cm]
\node (in1) [io] {Input};
\end{tikzpicture}
\end{document}
The code above generates the following node:
As the text inside grows so does the width of the Input node. But my question is if there is a way to set the width of the Input node beforehand or to give the Input node a maximum width.
You can use the trapezium stretches=true
option together with a fixed text width to make sure all your nodes have the same width.
If you have really long text, you could use the adjustbox
option to automatically scale the text down to fit into your node:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\tikzset{io/.style={
trapezium,
trapezium left angle=70,
trapezium right angle=110,
text width=3cm,
minimum height=1cm,
text centered,
draw=black,
fill=blue!30,
trapezium stretches=true
}}
\usepackage{adjustbox}
\begin{document}
\begin{tikzpicture}[node distance=2cm]
\node (in1) [io] {Input};
\node at (0,-2) [io] {\adjustbox{max width=3cm}{long text overflowing the shape}};
\node at (0,-4) [io] {Input Input};
\end{tikzpicture}
\end{document}