当我使用 tkz-euclide 对象(高度和角平分线)时,图形布局比实际图片尺寸大。我该如何使图像居中并适合?
\PassOptionsToPackage{table, dvipsnames, svgnames, x11names}{xcolor}
\documentclass [a4paper,10pt]{book}
\usepackage{subfig}
\usepackage{pstricks-add}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usepackage{pgfplots}
\usetikzlibrary{calc, intersections, plotmarks, matrix, quotes, angles, mindmap, arrows, folding, shapes, trees, hobby, backgrounds, positioning}
\usetkzobj{all}
\pgfkeys{/tikz/.cd, background color/.initial=lightgray!30, background color/.get=\backcol, background color/.store in=\backcol,}
\tikzset{background rectangle/.style={fill=\backcol,},use background/.style={show background rectangle}}
\begin{document}
\begin{figure}
\subfloat[][{\emph{Altitude}}]
{\begin{tikzpicture}[scale=1, x=1.0cm,y=1.0cm, use background]
\tkzDefPoint(0,0){A} \tkzDefPoint(4,0){B} \tkzDefPoint(1,3){C} \tkzDrawPolygon(A,B,C)
\tkzSetUpLine[color=blue] \tkzDrawAltitude(A,B)(C) \tkzGetPoint{H} \tkzMarkRightAngle(A,H,C) \tkzLabelPoints[below](A,B,H) \tkzLabelPoints[above](C)
\end{tikzpicture}}
\subfloat[][{\emph{Median}}]
{\begin{tikzpicture}[scale=1,x=1.0cm,y=1.0cm, use background]
\tkzDefPoint(0,0){A} \tkzDefPoint(4,0){B} \tkzDefPoint(1,3){C} \tkzDrawPolygon(A,B,C)
\tkzSetUpLine[color=red] \tkzDrawMedian(A,B)(C) \tkzGetPoint{M}
\tkzMarkSegments[mark=||](A,M M,B)
\tkzLabelPoints[below](A,B,M) \tkzLabelPoints[above](C)
\end{tikzpicture}}
\subfloat[][{\emph{Bisector}}]
{\begin{tikzpicture}[scale=1, x=1.0cm,y=1.0cm, use background]
\tkzDefPoint(0,0){A} \tkzDefPoint(4,0){B} \tkzDefPoint(1,3){C} \tkzDrawPolygon(A,B,C)
\tkzSetUpLine[color=Green] \tkzDrawBisector(A,C,B) \tkzGetPoint{D} \tkzMarkAngles[size=0.5cm, color=red,fill=purple, fill opacity=0.1, mark=|](A,C,D D,C,B)
\tkzLabelPoints[below](A,B,D) \tkzLabelPoints[above](C)
\end{tikzpicture}}
\end{figure}
\end{document}
答案1
一个相关的问题是使用 \tkzInterLC[R] 后 tikz 图片中出现不必要的空白,并且可以使用相同的策略:放置\tkzDrawAltitude
并置于环境\tkzDrawBisector
中pgfinterruptboundingbox
。
\PassOptionsToPackage{table, dvipsnames, svgnames, x11names}{xcolor}
\documentclass [a4paper,10pt]{book}
\usepackage{subfig}
\usepackage{pstricks-add}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usepackage{pgfplots}
\usetikzlibrary{calc, intersections, plotmarks, matrix, quotes, angles, mindmap, arrows, folding, shapes, trees, hobby, backgrounds, positioning}
\usetkzobj{all}
\pgfkeys{/tikz/.cd, background color/.initial=lightgray!30, background color/.get=\backcol, background color/.store in=\backcol,}
\tikzset{background rectangle/.style={fill=\backcol,},use background/.style={show background rectangle}}
\begin{document}
\begin{figure}
\subfloat[][{\emph{Altitude}}]
{\begin{tikzpicture}[scale=1, x=1.0cm,y=1.0cm, use background]
\tkzDefPoint(0,0){A} \tkzDefPoint(4,0){B} \tkzDefPoint(1,3){C} \tkzDrawPolygon(A,B,C)
\tkzSetUpLine[color=blue]
\begin{pgfinterruptboundingbox}
\tkzDrawAltitude(A,B)(C)
\end{pgfinterruptboundingbox}
\tkzGetPoint{H} \tkzMarkRightAngle(A,H,C) \tkzLabelPoints[below](A,B,H) \tkzLabelPoints[above](C)
\end{tikzpicture}}
\subfloat[][{\emph{Median}}]
{\begin{tikzpicture}[scale=1,x=1.0cm,y=1.0cm, use background]
\tkzDefPoint(0,0){A} \tkzDefPoint(4,0){B} \tkzDefPoint(1,3){C} \tkzDrawPolygon(A,B,C)
\tkzSetUpLine[color=red] \tkzDrawMedian(A,B)(C) \tkzGetPoint{M}
\tkzMarkSegments[mark=||](A,M M,B)
\tkzLabelPoints[below](A,B,M) \tkzLabelPoints[above](C)
\end{tikzpicture}}
\subfloat[][{\emph{Bisector}}]
{\begin{tikzpicture}[scale=1, x=1.0cm,y=1.0cm, use background]
\tkzDefPoint(0,0){A} \tkzDefPoint(4,0){B} \tkzDefPoint(1,3){C} \tkzDrawPolygon(A,B,C)
\tkzSetUpLine[color=Green]
\begin{pgfinterruptboundingbox}
\tkzDrawBisector(A,C,B)
\end{pgfinterruptboundingbox}
\tkzGetPoint{D} \tkzMarkAngles[size=0.5cm, color=red,fill=purple, fill opacity=0.1, mark=|](A,C,D D,C,B)
\tkzLabelPoints[below](A,B,D) \tkzLabelPoints[above](C)
\end{tikzpicture}}
\end{figure}
\end{document}
答案2
与其使用,\subfloat
我更愿意将tikzpicture
环境放在环境中tabular
,因为我认为这样更容易、更清晰地编写代码。使用 isa 的缺点tabular
是您会丢失任何索引,但由于这些图表位于 a 中,因此figure
它们将在图表列表中被索引。
tikzpicture
您可以使用 来控制每张图片的大小,\clip
以表示您希望每张图片有多大。通过反复试验(第一次尝试肯定会出错!),我将其剪裁为具有相对顶点(-0.2,-0.5)
和的矩形(4.2,3.5)
。
最后,我将用来\tikzset
定义每个环境的规格tikzpicture
,以便您可以在需要时在一个地方调整这些设置。
代码如下:
\PassOptionsToPackage{table, dvipsnames, svgnames, x11names}{xcolor}
\documentclass [a4paper,10pt]{book}
\usepackage{subfig}
\usepackage{pstricks-add}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usepackage{pgfplots}
\usetikzlibrary{calc, intersections, plotmarks, matrix, quotes, angles, mindmap, arrows, folding, shapes, trees, hobby, backgrounds, positioning}
\usetkzobj{all}
\pgfkeys{/tikz/.cd, background color/.initial=lightgray!30, background color/.get=\backcol, background color/.store in=\backcol,}
\tikzset{background rectangle/.style={fill=\backcol,},use background/.style={show background rectangle}}
\begin{document}
\tikzset{triangle/.style ={scale=1, use background, x=10mm, y=10mm}
}
\begin{figure}
\begin{tabular}{ccc}
\begin{tikzpicture}[triangle]
\clip (-0.2,-0.5) rectangle (4.2,3.5);
\tkzDefPoint(0,0){A} \tkzDefPoint(4,0){B} \tkzDefPoint(1,3){C}
\tkzDrawPolygon(A,B,C)
\tkzSetUpLine[color=blue] \tkzDrawAltitude(A,B)(C) \tkzGetPoint{H}
\tkzMarkRightAngle(A,H,C) \tkzLabelPoints[below](A,B,H) \tkzLabelPoints[above](C)
\end{tikzpicture}
&
\begin{tikzpicture}[triangle]
\clip (-0.2,-0.5) rectangle (4.2,3.5);
\tkzDefPoint(0,0){A} \tkzDefPoint(4,0){B} \tkzDefPoint(1,3){C} \tkzDrawPolygon(A,B,C)
\tkzSetUpLine[color=red] \tkzDrawMedian(A,B)(C) \tkzGetPoint{M}
\tkzMarkSegments[mark=||](A,M M,B)
\tkzLabelPoints[below](A,B,M) \tkzLabelPoints[above](C)
\end{tikzpicture}
&
\begin{tikzpicture}[triangle]
\clip (-0.2,-0.5) rectangle (4.2,3.5);
\tkzDefPoint(0,0){A} \tkzDefPoint(4,0){B} \tkzDefPoint(1,3){C}
\tkzDrawPolygon(A,B,C) \tkzSetUpLine[color=Green] \tkzDrawBisector(A,C,B)
\tkzGetPoint{D}
\tkzMarkAngles[size=0.5cm, color=red,fill=purple, fill opacity=0.1, mark=|](A,C,D D,C,B)
\tkzLabelPoints[below](A,B,D) \tkzLabelPoints[above](C)
\end{tikzpicture}
\\[2mm]
(a) \textit{Altitude} & (b) \textit{Median} & (c) \textit{Bisector}
\end{tabular}
\end{figure}
\end{document}