6

I am using following (hexagon) loop definition I found in Stackexchange in my flowchart. When the number of text lines in it increases, the width of the whole shape also increases. I want the width of the shape itself to be fixed. Can you help in defining such a hexagon? It does not have to follow the starting definition I give in the MWE.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, calc, shapes.misc, matrix, shapes, arrows, calc, positioning, shapes.geometric, shapes.symbols, shapes.misc, intersections, chains, scopes}


\tikzset{
    loop/.style={ % requires library shapes.misc
        draw,
        chamfered rectangle,
        chamfered rectangle xsep=2cm,
        text width=10em,
    },
}


\begin{document}


\begin{tikzpicture}[node distance=1.6cm]

\node (l1)[loop]{aa};
% node below is wider then the one above. I want the width of the one below to be same as the one above.
\node (l2)[loop,below of=l1]{aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa };

\end{tikzpicture}

\end{document}

Result picture

ozi
  • 529
  • You can keep chamfered rectangle xsep=2cm small to make them have equal width. But no sharp edges. –  Apr 14 '14 at 02:43
  • I am OK with no sharp edges. But arrangement of any attributes like chamfered rectantle xsep should be automatic. I think my title is misleading. You do not have to do it with chamfered rectangle. I need a hexagon that arranges its height and keeps its width fixed. – ozi Apr 14 '14 at 11:05
  • Hence, I changed the title. – ozi Apr 14 '14 at 11:17

1 Answers1

1

Workaround A (drawing outside the defined style)

I tried to add drawing after the use of \node which can be customized outside your loop style.

%! *latex mal-chamfered.tex
\documentclass{article}
\pagestyle{empty}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, calc, shapes.misc, matrix, shapes, arrows, calc, positioning, shapes.geometric, shapes.symbols, shapes.misc, intersections, chains, scopes}
\tikzset{
    loop/.style={ % requires library shapes.misc
        draw,
        chamfered rectangle,
        %chamfered rectangle ysep=2mm,
        chamfered rectangle xsep=10mm,
        text width=10em, 
        align=center,
    },
}
\begin{document}
\def\malxsep{3mm}
\begin{tikzpicture}[node distance=1.6cm]
\node (l1)[loop]{aa};
\node (l2)[text width=10em-0.5em, align=center,below of=l1]{aaa aaa aaa \\aaa aaa aaa aaa aaa aaa \\aaa\\ aaa aaa\\ aaa aaa aaa aaa };
\draw (l2.north west)--($(l2.west)+(-\malxsep,0)$)--(l2.south west)--(l2.south east)--($(l2.east)+(\malxsep,0)$)--(l2.north east)--cycle;
\end{tikzpicture}
\end{document}

mwe


Edit: Workaround B (drawing inside the defined style)

I used the \tikzset to define following: I started to modify the loop style, inside that expression I added append after command, inside that part I incorporated the \pgfextra command and finally I drew a hexagon in the \node itself. I enclose the result of my efforts and a preview of it.

%! *latex mal-chamfered.tex
\documentclass{article}
\pagestyle{empty}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{
    loop/.style={
        anchor=north,
        text width=10em, 
        align=center,
        append after command={
           \pgfextra{
              \draw (\tikzlastnode.north west)--($(\tikzlastnode.west)+(-\malxsep,0)$)--
                    (\tikzlastnode.south west)--(\tikzlastnode.south east)--
                    ($(\tikzlastnode.east)+(\malxsep,0)$)--
                    (\tikzlastnode.north east)--cycle;
           }% End of \pgfextra...
        },% End of append after command...
    },% End of loop/.style...
}% End of \tikzset...
\begin{document}
\def\malxsep{3mm}
\begin{tikzpicture}[node distance=2cm]
\node(l1)[loop]{aa};
\node(l2)[loop] at (l1.south) {A\\B\\C};
\node(l3)[loop] at (l2.south) {aaa aaa aaa \\aaa aaa aaa aaa aaa aaa \\aaa\\ aaa aaa\\ aaa aaa aaa aaa };
\end{tikzpicture}
\end{document}

mwe, part 2

Malipivo
  • 13,287
  • The picture you posted is what I want, but I would not like to redraw it manually everytime like you did. I need it defined in a tikzset definition, and just reuse it. The shape should nicely grow vertically when needed, but stay with same width. – ozi Apr 14 '14 at 11:02
  • Solution B works with a small caveat. E.g. l2.east and l2.west are not right on the line. They are a little inside. E.g. when I do something like \draw (l2.east) -- (l3.west); the connector misses the boundary line. Can there be a way to redefine them also? – ozi Apr 14 '14 at 19:46
  • The basic shape is still a rectangle (not hexagon) and you can connect its four corners. For now you can use \draw ($(l2.east)+(\malxsep,0)$) -- ($(l3.west)+(-\malxsep,0)$);. It would be worth preparing a new pgf shape, perhaps. – Malipivo Apr 14 '14 at 20:16
  • You could see that rectangle in a minute when trying fill=blue. It is probably not the best approach of mine. But we can write \draw[fill=blue] in the inner part of style. – Malipivo Apr 14 '14 at 20:27
  • No need. I can understand why it is behaving like this. It is just does not answer my question. – ozi Apr 14 '14 at 21:05
  • Yes, my proposals are workarounds. – Malipivo Apr 14 '14 at 21:08