3

When I use the tkz-euclide object (altitude and bisector) the figure layout is larger than the real picture dimension. How can I do to center and fit my images?

\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}

enter image description here

2

A related question is unnecessary white space in tikz picture after using \tkzInterLC[R], and you can use the same strategy: place \tkzDrawAltitude and \tkzDrawBisector in a pgfinterruptboundingbox environment.

\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}

enter image description here

0

Rather than using \subfloat I would put the tikzpicture environments inside a tabular environment because I think that these are easier and cleaner to code. The downside of using tabular isa that you loose any indexing but as you have these diagrams inside a figure they will be indexed in the list of figures.

You can control the size of each tikzpicture using \clip to say how big you want each picture to be. By trial and error (certainly error on the first attempt!), I clipped to a rectangle with opposing vertices (-0.2,-0.5) and (4.2,3.5).

Finally, I'd use \tikzset to define the specifications of each tikzpicture environment so that, if you need to, then you can tweak these settings in just one place. enter image description here

Here's the code:

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.