14

I need to draw some nodes for a diagram, but I'm failing to produce a simple horizontally enlarged hexagon.

If I use regular polygon (from shapes.geometric), I cannot enlarge it (first figure in image below). I tried to set shape aspect just to no avail.

A workaround I found in the pgfmanual, is to use the chamfered rectangle (from shapes.misc), but then we must be cautious about the balance between xsep and how much text there is inside the rectangle (second and third figure in image below).

This is the code that produces the figures below:

\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes.misc}

\begin{tikzpicture}[node distance=1.5cm]
  \node[regular polygon, regular polygon sides=6, shape aspect=0.5, minimum width=4cm, minimum height=1cm, draw] (reg) {Regular node};
  \node[chamfered rectangle, chamfered rectangle xsep=2cm, draw] (chamf) [right=of reg] {Enlarged node};
  \node[chamfered rectangle, chamfered rectangle xsep=1cm, text width=2cm, draw] (chamfB) [below=of chamf] {Enlarged node with many lines that flow down};
\end{tikzpicture}

Figures

0
14

To scale the hexagon horizontally, you can use the xscale option; you can add the text using the label=center:<text> option to the hexagon node:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes.misc}

\begin{document}

\begin{tikzpicture}
  \node[regular polygon, regular polygon sides=6, minimum width=2cm,draw,label=center:some text] (reg1) at (0,0){};
  \node[regular polygon, regular polygon sides=6, minimum width=1cm, xscale=3,draw,label=center:some text] (reg2) at (3,0) {};
\end{tikzpicture}

\end{document}

enter image description here

3
  • Thanks Gonzalo, but it also scales the polygon. I've just edited my question so that stays clear that I need to enlarge the polygon just in the X-axis. – Nicolás Ozimica Nov 3 '11 at 3:27
  • @Nicolás: see my updated answer. – Gonzalo Medina Nov 3 '11 at 3:39
  • Obviously, there is an option to scale along the y axis also: yscale. – Count Zero Nov 4 '11 at 22:41
4

You can add a scale to each node. Here is a version with and with the default of scale=1 and scale=1.3 appliled:

enter image description here

\documentclass[border=5pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes.misc}

\begin{document}
\begin{tikzpicture}[node distance=1.5cm]
  \node[regular polygon, regular polygon sides=6, shape aspect=0.5, minimum width=4cm, minimum height=1cm, draw,scale=1] (reg) {Regular node};
\end{tikzpicture}
%
\begin{tikzpicture}[node distance=1.5cm]
  \node[regular polygon, regular polygon sides=6, shape aspect=0.5, minimum width=4cm, minimum height=1cm, draw,scale=1.3] (reg) {Regular node};
\end{tikzpicture}
\end{document}

If you have an issue with adding multiple lines of text to the node then you need to specify the width of the text and an alignment with:

text width=2.4cm,align=center

This is independent of the scaling issue and yields:

enter image description here

\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes.misc}

\begin{document}
\begin{tikzpicture}[node distance=1.5cm]
  \node[regular polygon, regular polygon sides=6, shape aspect=0.5, minimum width=4cm, minimum height=1cm, draw,scale=1,text width=2.4cm,align=center] (reg) {Enlarged node with many lines that flow down};
\end{tikzpicture}
%
\begin{tikzpicture}[node distance=1.5cm]
  \node[regular polygon, regular polygon sides=6, shape aspect=0.5, minimum width=4cm, minimum height=1cm, draw,scale=1.3,text width=2.4cm,align=center] (reg) {Enlarged node with many lines that flow down};
\end{tikzpicture}
\end{document}

If you prefer to manually decide where the line break should be, by adding a \\, then you do not need to specify text width=2.4cm. So use:

\node ... {Enlarged node \\ with many lines \\ that flow down}

Here is the full code for this:

\documentclass[border=5pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes.misc}

\begin{document}
\begin{tikzpicture}[node distance=1.5cm]
  \node[regular polygon, regular polygon sides=6, shape aspect=0.5, minimum width=4cm, minimum height=1cm, draw,scale=1,text width=2.4cm,align=center] (reg) {Enlarged node \\ with many lines \\ that flow down};
\end{tikzpicture}
%
\begin{tikzpicture}[node distance=1.5cm]
  \node[regular polygon, regular polygon sides=6, shape aspect=0.5, minimum width=4cm, minimum height=1cm, draw,scale=1.3,align=center] (reg) {Enlarged node \\ with many lines \\ that flow down};
\end{tikzpicture}
\end{document}
1
  • Thanks Peter, but this is not what I need. I'm looking for a way to enlarge horizontally the hexagon, not scale it up or down. – Nicolás Ozimica Nov 3 '11 at 3:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.