在以下tikzpicture
环境中,我有一个六边形和一个五边形,它们沿水平对称轴对齐。(在六边形中,顶点A
最靠右,顶点B
是最低顶点,顶点C
和E
最靠左,D
是朝向中心的顶点,F
是最高顶点。五边形的标签类似。)有两个方面不正确。五边形的标题在其自身上。E
是五边形上的最高顶点,我使用命令\node[font=\bfseries, above=of E -| {$(C |- A)!0.5!(A)$}] (title) {A convex set};
放置标题。为什么标题没有放在五边形上方?另外,为什么tikzpicture
与右边距齐平?
\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}
答案1
为什么标题不放在五边形上方?
因为点数F
最高,而不是E
。
为什么 tikzpicture 与右边距齐平?
那是因为您正在设置\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}
答案2
我想让图片在页面上水平居中。我更喜欢使用 中的熟悉命令来执行此操作TikZ
。以下代码可以实现我想要的显示效果。
\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}