1

In the following tikzpicture environment, I have a hexagon and a pentagon aligned along their horizontal axes of symmetry. (In the hexagon, the vertex A is furthest to the right, the vertex B is the lowest vertex, vertices C and E are furthest to the left, D is the vertex towards the center, and F is the highest vertex. Similar labeling for the pentagon.) There are two aspects that are not right. The title for the pentagon is on itself. E is the highest vertex on the pentagon, and I use the command \node[font=\bfseries, above=of E -| {$(C |- A)!0.5!(A)$}] (title) {A convex set}; to place the title. Why is the title not placed above the pentagon? Also, why is the tikzpicture flush against the right margin?

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

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


\begin{document}


\noindent \hspace*{\fill}
\begin{tikzpicture}[node distance= 3mm and 0mm]

%A hexagon - a set that is not convex - 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$};

%Title for hexagon is typeset.
\node[font=\bfseries,align=center,above=of F -| {$(C |- A)!0.5!(A)$}] (title) {A set that is \\ not convex};


%A convex pentagon is drawn which is symmetric across the x-axis.
\begin{scope}[transform canvas={xshift=6cm}]
\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);

%Title for pentagon is typeset.
\node[font=\bfseries, above=of E -| {$(C |- A)!0.5!(A)$}] (title) {A convex set};
\end{scope}
\end{tikzpicture}
\hspace{\fill}

\end{document}

2 Answers 2

3

enter image description here

Why is the title not placed above the pentagon?

Because point F is highest and not E.

why is the tikzpicture flush against the right margin?

That is because you are setting \hspace*{\fill}.

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

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

\begin{document}

\noindent %\hspace*{\fill}
\begin{tikzpicture}[node distance= 3mm and 0mm]

%A hexagon - a set that is not convex - 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$};

%Title for hexagon is typeset.
\node[font=\bfseries,align=center,above=of F -| {$(C |- A)!0.5!(A)$}] (title) {A set that is \\ not convex};


%A convex pentagon is drawn which is symmetric across the x-axis.
\begin{scope}[transform canvas={xshift=6cm}]
\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);

%Title for pentagon is typeset.
\node[font=\bfseries, above=of F -| {$(C |- A)!0.5!(A)$} ] (title) {A convex set};
\end{scope}
\end{tikzpicture}
\hspace{\fill}

\end{document}
11
  • In the scope environment for the pentagon, the F is the highest vertex. I had E in the command for placing the title. Thanks for finding that mistake. After the tikzpicture environment, I have the command \hspace{\fill}. That should "balance" the \noindent \hspace*{\fill} before the tikzpicture environment. It doesn't - not on my computer.
    – user74973
    Commented Jul 28, 2015 at 13:05
  • I am not familiar with the code for placing the title. Does the option node distance= 3mm and 0mm for the tikzpicture environment only apply to nodes with (title) specified? I think that the point $(C |- A)!0.5!(A)$ is determined using the calc package. When I use such code for plotting points, I put it in a pair of parentheses - ($(C |- A)!0.5!(A)$). I get an error when using it after above=of, though.
    – user74973
    Commented Jul 28, 2015 at 13:07
  • If I denote $(C |- A)!0.5!(A)$ by M, the code for placing the title for the convex set is above=of F -| M. It seems precarious to me not to have either braces or parentheses enclosing F -| M. I tried above=of(F -| M) and got an error. I enclosed it in braces and the code compiled. If there is no space between the of and left brace, though, I get an error. above=of{F -| M} does not compile. What is the syntax for using above=of in a node?
    – user74973
    Commented Jul 28, 2015 at 13:07
  • 1
    @user74973 For node distances, see Sec. 27.3, Padding and Node Distances of the PGF manual. above=of needs the node name without parentheses. Or, in your case, the calculated node using the two dollars $(C |- A)!0.5!(A)$. It is Okay to use braces {} around a calculation {$some formula$}. See also Sec. 13.5 Coordinate Calculations of the documentation.
    – AboAmmar
    Commented Jul 28, 2015 at 14:21
  • 1
    @user74973 Usually, we say \begin{figure}[!htbp]\centering \begin{tikzpicture} ... \end{tikzpicture}\end{figure} to insert the picture into a figure and center it. Of course we get many advantages using the figure like cross referencing and captions, etc. In your example, this will fail, though, because of using the transform canvas= command which switches off tracking of the picture size. See page 363, Sec. 25.4, Canvas Transformations of the manual.
    – AboAmmar
    Commented Jul 28, 2015 at 16:59
0

I want to center the figures horizontally on the page. I prefer to do this with familiar commands in TikZ. Here is code that gives the display that I want.

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

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


\begin{document}


\noindent \hspace*{\fill}
\begin{tikzpicture}

%A hexagon - a set that is not convex - 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_BC] (B) -- (C');
\coordinate[name intersections={of=extension_of_BC and horizontal_line_at_-1, by={C}}];
\draw (B) -- (C);

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

\coordinate (E') at ($(D) + (135:2)$);
\path[name path=extension_of_DE] (D) -- (E');
\coordinate[name intersections={of=extension_of_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$};

%Title for hexagon is typeset.
%M_1 is the intersection of the vertical line through C and the horizontal line through A.
%It is on the x-axis and as far leftward as points C and E. M_2 is the midpoint of line
%segment AM_1. M_3 is the intersection of the vertical line through M_2 and the horizontal
%line through F.
\coordinate (M_1) at (C |- A);
\coordinate (M_2) at ($(M_1)!0.5!(A)$);
\coordinate (M_3) at (M_2 |- F);
\coordinate (title_for_hexagon) at ($(M_3)!-3mm!(M_2)$);
\node[font=\bfseries,anchor=south,inner sep=0,align=center] at (title_for_hexagon){A set that is \\ not convex};


%A convex pentagon is drawn which is symmetric across the x-axis.
\coordinate (rightward_shift_of_A) at (6,0);
\coordinate (rightward_shift_of_O) at (1,0);

\path[name path=rightward_shift_of_x-axis] (rightward_shift_of_A) -- (rightward_shift_of_O);
\path[name path=rightward_shift_of_horizontal_line_at_-1] (1,-1) -- (6,-1);
\path[name path=rightward_shift_of_horizontal_line_at_1] (1,1) -- (6,1);

\coordinate (rightward_shift_of_B) at ($(rightward_shift_of_A) + (-135:2.5)$);
\draw (rightward_shift_of_A) -- (rightward_shift_of_B);

\coordinate (rightward_shift_of_C') at ($(rightward_shift_of_B) + (165:3)$);
\path[name path=extension_of_the_rightward_shift_of_BC] (rightward_shift_of_B) -- (rightward_shift_of_C');
\coordinate[name intersections={of=extension_of_the_rightward_shift_of_BC and rightward_shift_of_horizontal_line_at_-1, by={rightward_shift_of_C}}];
\draw (rightward_shift_of_B) -- (rightward_shift_of_C);

\coordinate (rightward_shift_of_D') at ($(rightward_shift_of_C) + (45:2)$);
\path[name path=extension_of_the_rightward_shift_of_CD] (rightward_shift_of_C) -- (rightward_shift_of_D');
\coordinate[name intersections={of=extension_of_the_rightward_shift_of_CD and rightward_shift_of_x-axis, by={rightward_shift_of_D}}];
\draw[dashed] (rightward_shift_of_C) -- (rightward_shift_of_D);

\coordinate (rightward_shift_of_E') at ($(rightward_shift_of_D) + (135:2)$);
\path[name path=extension_of_the_rightward_shift_of_DE] (rightward_shift_of_D) -- (rightward_shift_of_E');
\coordinate[name intersections={of=extension_of_the_rightward_shift_of_DE and rightward_shift_of_horizontal_line_at_1, by={rightward_shift_of_E}}];
\draw[dashed] (rightward_shift_of_D) -- (rightward_shift_of_E);

\draw (rightward_shift_of_C) -- (rightward_shift_of_E);

\coordinate (rightward_shift_of_F) at ($(rightward_shift_of_E) + (15:3)$);
\draw (rightward_shift_of_E) -- (rightward_shift_of_F);
\draw (rightward_shift_of_A) -- (rightward_shift_of_F);

%Title for pentagon is typeset.
%rightward_shift_of_M_1 is the intersection of the vertical line through rightward_shift_of_C and
%the horizontal line through rightward_shift_of_A. It is on the x-axis and as far leftward as
%points rightward_shift_of_C and rightward_shift_of_E. rightward_shift_of_M_3 is the intersection
%of the vertical line through rightward_shift_of_M_2 and the horizontal line through
%rightward_shift_of_F.
\coordinate (rightward_shift_of_M_1) at (rightward_shift_of_C |- rightward_shift_of_A);
\coordinate (rightward_shift_of_M_2) at ($(rightward_shift_of_M_1)!0.5!(rightward_shift_of_A)$);
\coordinate (rightward_shift_of_M_3) at (rightward_shift_of_M_2 |- rightward_shift_of_F);
\coordinate (title_for_pentagon) at ($(rightward_shift_of_M_3)!-3mm!(rightward_shift_of_M_2)$);
\node[font=\bfseries,inner sep=0] at (title_for_pentagon){A convex set};

\end{tikzpicture}
\hspace{\fill}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .