# Typesetting a title on a tikzpicture (Version 2)

I have two very similar-looking polygons in different TikZ environments. Each polygon is symmetric across a horizontal line. I want to put them in one TikZ environment with the axes of symmetry aligned. I didn't know how to do this while keeping the titles of each figure in their respective positions.

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}

\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections}

\begin{document}

\begin{tikzpicture}

%A hexagon is drawn which is symmetric across the x-axis.
\coordinate (A) at (0,0);
\coordinate (O) at (-5,0);

\path[name path=x-axis] (A) -- (O);
\path[name path=horizontal_line_at_-1] (-5,-1) -- (0,-1);
\path[name path=horizontal_line_at_1] (-5,1) -- (0,1);

\coordinate (B) at ($(A) + (-135:2.5)$);
\draw (A) -- (B);

\coordinate (C') at ($(B) + (165:3)$);
\path[name path=extension_of_line_segment_BC] (B) -- (C');
\coordinate[name intersections={of=extension_of_line_segment_BC and horizontal_line_at_-1, by={C}}];
\draw (B) -- (C);

\coordinate (D') at ($(C) + (45:2)$);
\path[name path=extension_of_line_segment_CD] (C) -- (D');
\coordinate[name intersections={of=extension_of_line_segment_CD and x-axis, by={D}}];
\draw (C) -- (D);

\coordinate (E') at ($(D) + (135:2)$);
\path[name path=extension_of_line_segment_DE] (D) -- (E');
\coordinate[name intersections={of=extension_of_line_segment_DE and horizontal_line_at_1, by={E}}];
\draw (D) -- (E);

\coordinate (F) at ($(E) + (15:3)$);
\draw (E) -- (F);
\draw (A) -- (F);

%Points P and Q in the hexagon are plotted. Line segment $\overline{PQ}$ is not contained in the
%hexagon.
\coordinate (P) at (-4,0.75);
\draw[fill] (P) circle (1.5pt);
\coordinate (Q) at (-4,-0.75);
\draw[fill] (Q) circle (1.5pt);
\draw (P) -- (Q);
%Points P and Q are labeled.
\coordinate (label_for_P) at ($(P)!-3mm!-90:(Q)$);
\node at (label_for_P){$P$};
\coordinate (label_for_Q) at ($(Q)!-3mm!90:(P)$);
\node at (label_for_Q){$Q$};

%A title is typeset.
\node[align=center,font=\bfseries, yshift=2em] (title) at (current bounding box.north){A set that is \\ not convex};
\end{tikzpicture}

\begin{tikzpicture}

%A hexagon is drawn which is symmetric across the x-axis.
\coordinate (A) at (0,0);
\coordinate (O) at (-5,0);

\path[name path=x-axis] (A) -- (O);
\path[name path=horizontal_line_at_-1] (-5,-1) -- (0,-1);
\path[name path=horizontal_line_at_1] (-5,1) -- (0,1);

\coordinate (B) at ($(A) + (-135:2.5)$);
\draw (A) -- (B);

\coordinate (C') at ($(B) + (165:3)$);
\path[name path=extension_of_line_segment_BC] (B) -- (C');
\coordinate[name intersections={of=extension_of_line_segment_BC and horizontal_line_at_-1, by={C}}];
\draw (B) -- (C);

\coordinate (D') at ($(C) + (45:2)$);
\path[name path=extension_of_line_segment_CD] (C) -- (D');
\coordinate[name intersections={of=extension_of_line_segment_CD and x-axis, by={D}}];
\draw[dashed] (C) -- (D);

\coordinate (E') at ($(D) + (135:2)$);
\path[name path=extension_of_line_segment_DE] (D) -- (E');
\coordinate[name intersections={of=extension_of_line_segment_DE and horizontal_line_at_1, by={E}}];
\draw[dashed] (D) -- (E);

\draw (C) -- (E);

\coordinate (F) at ($(E) + (15:3)$);
\draw (E) -- (F);
\draw (A) -- (F);

%A title is typeset.
\node[font=\bfseries, yshift=2em] (title) at (current bounding box.north){A convex set};
\end{tikzpicture}

\end{document}


And one more solution (It take me little more time because I allowed myself first to simplify the picture code :-) , i was lost in original one :-( ):

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections}

\begin{document}
\begin{tikzpicture}[
node distance= 3mm and 5mm,
]
%%%% first shape
\coordinate (O)     at (-5,0);
\coordinate (A)     at (0,0);
\coordinate (B)     at ($(A)+(135:2.5)$);
\coordinate (C)     at ($(B)+(-165:3)$);
%
\coordinate (B')    at ($(A)+(-135:2.5)$);
\coordinate (C')    at ($(B')+(165:3)$);
%
\path[name path=x-axis] (O) -- (A);
\path[name path=c-b_line] (C') -- (B);
\coordinate[name intersections={of=c-b_line and x-axis,by={D}}];

\draw (A) -- (B) -- (C) -- (D) -- (C') -- (B') -- cycle;

\coordinate (P) at (-4,0.75);
\coordinate (Q) at (-4,-0.75);
\draw[fill=black]   (P) circle (1.5pt) node[right] {$P$}  --
(Q) circle (1.5pt) node[right] {$Q$};
%% Title of second shape.
\node[font=\bfseries,align=center,
above=of B -| {$(C |- A)!0.5!(A)$}] (title)   {A set that is \\
not convex};
%% Title of first shape.
\node[font=\bfseries,align=center,
above=of B -| {$(C |- A)!0.5!(A)$}] (title)   {A set that is \\
not convex};
%%%% secod shape
\begin{scope}[transform canvas={xshift=6cm}]
\coordinate (O)     at (-5,0);
\coordinate (A)     at (0,0);

\coordinate (B)     at ($(A)+(135:2.5)$);
\coordinate (C)     at ($(B)+(-165:3)$);
%
\coordinate (B')    at ($(A)+(-135:2.5)$);
\coordinate (C')    at ($(B')+(165:3)$);
%
\path[name path=x-axis] (O) -- (A);
\path[name path=c-b_line] (B) -- (C');
\coordinate[name intersections={of=c-b_line and x-axis,by={D}}];

\draw (A) -- (B) -- (C) -- (C') -- (B') -- cycle;
\draw[dashed] (C) -- (D) -- (C');
%% Title of second shape.
\node[font=\bfseries,
above=of B -| {$(C |- A)!0.5!(A)$}] (title)  {A convex set};
\end{scope}
\end{tikzpicture}
\end{document}


Edit: Now I figured out, how to move second shape with xshift ... I correct my MWE accordingly. The picture is the same as before.

Edit (2): Some explanation of MWE. The node distance from library possitionig determine common distance between nodes if you say: \node[above right=of node name]. In this case, the horizontal distance is not used.

The node for (sub)image titles can have the same parameters and can be set up on beginning of picture, something like:

\begin{tikzpicture}[
title/.style = {font=\bfseries, align=center}]


and then in code use

\node[title, above=of M |-C] {title};


if the M is midpoint between A and O. Midpoint M can be determined as shown in above, however it can be simply set up width

\coordinate[right=25mm of A] (M);


As can be seen, I significantly strip the MWE in question simply because most of them I din't understand and they seems to me to be surplus. In compose of it I follow to given pictures.

• You should edit your code. You have the same command following "%% Title of second shape" as you have following "%% Title of first shape". – user74973 Jul 27 '15 at 22:48
• You have above=of B -| {$(C |- A)!0.5!(A)$} as an option in the node command to place the first title. (Recall that C and E are the two vertices on the hexagon that are furthest to the left. A is the vertex on the hexagon furthest to the right.) I know that C |- A is the intersection of the vertical line through C and the horizontal line through A. So, {$(C |- A)!0.5!(A)$} is the "horizontal midpoint" of the first display. If I call this point M, what is B -| M and above=of B -| M? – user74973 Jul 27 '15 at 22:57
• (I see that in your code B is the highest vertex on the hexagon.) I guess that B -| M is the intersection of a horizontal line through B and a vertical line through M. OK. If my comments are correct, I would expect the middle of the title "A set that is not convex" to be typeset much lower. I don't know what above of does, though. By the way, shouldn't the syntax be something like above of={B -| M}? – user74973 Jul 27 '15 at 23:10
• You also have node distance= 3mm and 5mm as an option to the tikzpicture environment. How is this interpreted by TikZ? – user74973 Jul 27 '15 at 23:11
• OK. I'll give you an opportunity to answer my questions. Thanks. – user74973 Jul 27 '15 at 23:11