2
\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{etex,amsmath,amsfonts,amssymb,graphicx,flexisym,setspace,scrextend,siunitx,multicol,tikz,tkz-euclide,adjustbox}

\usetkzobj{all}
\usetikzlibrary{calc}
\usepackage[margin=1cm,bmargin=1.4cm]{geometry}

\begin{document}
\begin{minipage}{0.3\linewidth}
\begin{enumerate}
\item \adjustbox{valign=t}{
\begin{tikzpicture}
    \tkzDefPoint(0,0){A}
    \tkzDefPoint(2.5,0){B}
    \tkzDrawTriangle[two angles = 60 and 60,overlay](A,B)
    \tkzGetPoint{C}
    \tkzLabelPoint[left](A){$A$}
    \tkzLabelPoint[right](B){$B$}
    \tkzLabelPoint[above](C){$C$}
    \tkzDrawAltitude(A,B)(C)
    \tkzGetPoint{D}
    \tkzLabelPoint[above right](D){$D$}
    \tkzMarkRightAngle[color=red](C,D,A)
    \tkzLabelAngle[pos=0.5](C,A,B){\small 60\si{\degree}}
    \tkzLabelAngle[pos=0.5](C,B,A){\small 60\si{\degree}}
    \tkzLabelSegment[auto](C,D){$s$}
    \tkzLabelSegment[auto](A,C){$r$}
    \tkzLabelSegment[auto](B,A){18}
\end{tikzpicture}}\vspace{1.25in}

\item \leavevmode\vadjust{\vspace{-\baselineskip}}\newline
\begin{tikzpicture}[rotate=-30]
    \tkzDefPoint(0,0){A}
    \tkzDefPoint(3,0){B}
    \tkzDrawTriangle[school,overlay](B,A)
    \tkzGetPoint{C}
    \tkzLabelPoint[above](A){$A$}
    \tkzLabelPoint[right](B){$B$}
    \tkzLabelPoint[left](C){$C$}
    \tkzDrawAltitude(B,C)(A)
    \tkzGetPoint{D}
    \tkzLabelPoint[below right](D){$D$}
    \tkzMarkRightAngle[color=red](A,D,C)
    \tkzLabelAngle[pos=-0.8](C,B,A){\small 30\si{\degree}}
    \tkzLabelAngle[pos=0.45](A,C,B){\small 60\si{\degree}}
    \tkzLabelSegment[auto,swap](B,A){8}
    \tkzLabelSegment[auto,swap](C,D){$y$}
    \tkzLabelSegment[auto](A,D){$x$}
\end{tikzpicture}\vspace{1in}
\end{enumerate}
\end{minipage}

\end{document}

Vertical alignment in minipages is close to what I need but hasn't solved my problem. I've asked a similar question (with good results up until now) Awkward vertical space in tcolorbox with tikzpicture. Why is there so much space between the enumerate number and the figure (#17 in the image).

I am creating math worksheets. I need to number tikzpictures and leave space for solutions, and I need these problems, despite their variable shapes, to be aligned in a nice way (vertical and horizontal spacing should be consistent, no matter what it is). I've tried using tabular and tabularx (enumerate works weirdly with them AND because I need the number to be above the picture a la Aligning an enumeration item to the top of a tikzpicture, these solutions (especially with linebreaks in them) didn't work for me in a tabular environment). I've been using multicols up until I found out about minipage; the problem I have with multicols is the spacing gets real funky and won't align by rows (from my understanding, it just takes the total amount of space requested by the code and divides it up by the number of specified columns, so sometimes the problem number will be in the previous column than the tikzpicture itself.)

To be fair, minipage looks like it should work! ... and has been until this last set of two problems. (My MWE includes only the code for #17 and #18... I can show the full code for all 6 problems if needed but as they're working nicely, I'm fairly certain they're not the problem. Let me know.) As you can see, 13-16 are nicely aligned using the exact same minipage/enumerate/tkzpicture configuration. For some reason, #17 is adding a crazy amount of vertical space (looks like it's aligning with the bottom of #15?) #18 looks like it's aligned just fine. What is going on with my tikzpicture in #17?

6 triangles that refuse to align

1
  • Jenni, can you share your TikZ code for the other triangles as well please? Thanks! Dec 28, 2019 at 23:25

2 Answers 2

3

The left-side figure, for some reason, has a bounding box much higher than the figure as can be seen if you put it in an \fbox. I trimmed it by trial and errors. I also suggest you use the tasks package to have automatic horizontal first, then vertical numbering. Last (unrelated) comment: since LaTeX 2015, you don't need to load etex anymore.

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{amsmath,amsfonts,amssymb,graphicx,flexisym,setspace,scrextend,siunitx,multicol,tikz,tkz-euclide,adjustbox}
\usepackage{tasks}

\usetkzobj{all}
\usetikzlibrary{calc}
\usepackage[margin=1cm,bmargin=1.4cm]{geometry}

\begin{document}
\begin{tasks}[counter-format ={tsk[1].}, after-skip = 1 in](3)%
 \task \adjustbox{valign=t, trim = 0pt 0pt 0pt 56.8pt}{
\begin{tikzpicture}
    \tkzDefPoint(0,0){A}
    \tkzDefPoint(2.5,0){B}
    \tkzDrawTriangle[two angles = 60 and 60,overlay](A,B)
 \tkzGetPoint{C}
 \tkzLabelPoint[left](A){$A$}
 \tkzLabelPoint[right](B){$B$}
 \tkzLabelPoint[above](C){$C$}
 \tkzDrawAltitude(A,B)(C)
 \tkzGetPoint{D}
 \tkzLabelPoint[above right](D){$D$}
 \tkzMarkRightAngle[color=red](C,D,A)
 \tkzLabelAngle[pos=0.5](C,A,B){\small 60\si{\degree}}
 \tkzLabelAngle[pos=0.5](C,B,A){\small 60\si{\degree}}
 \tkzLabelSegment[auto](C,D){$s$}
 \tkzLabelSegment[auto](A,C){$r$}
 \tkzLabelSegment[auto](B,A){18}
\end{tikzpicture}}

\task
\vadjust{\vspace{-\baselineskip}}\newline
\begin{tikzpicture}[rotate=-30]
    \tkzDefPoint(0,0){A}
    \tkzDefPoint(3,0){B}
    \tkzDrawTriangle[school,overlay](B,A)
    \tkzGetPoint{C}
    \tkzLabelPoint[above](A){$A$}
    \tkzLabelPoint[right](B){$B$}
    \tkzLabelPoint[left](C){$C$}
    \tkzDrawAltitude(B,C)(A)
    \tkzGetPoint{D}
    \tkzLabelPoint[below right](D){$D$}
    \tkzMarkRightAngle[color=red](A,D,C)
 \tkzLabelAngle[pos=-0.8](C,B,A){\small 30\si{\degree}}
 \tkzLabelAngle[pos=0.45](A,C,B){\small 60\si{\degree}}
 \tkzLabelSegment[auto,swap](B,A){8}
 \tkzLabelSegment[auto,swap](C,D){$y$}
 \tkzLabelSegment[auto](A,D){$x$}
\end{tikzpicture}
\end{tasks}

\end{document}

enter image description here

1
  • I changed the last trim number to 68 to get it where I visually wanted, but it was effective. Also, I'm using overleaf and it throws warnings if etex isn't at the beginning of the packages statement for whatever reason.
    – Jenni
    Dec 19, 2017 at 14:22
0

Another solution, similar to this answer, is to:

  • Put \draw (current bounding box.south east) rectangle (current bounding box.north west); before the end of your tikzpicture environment to temporarily to draw a bounding box
  • Wrap \begin{pgfinterruptboundingbox}....\end{pgfinterruptboundingbox} around the offending code to prevent it from stretching your bounding box
  • Comment or remove the \draw (current bounding box.south east) rectangle (current bounding box.north west); once you are finished.

The following is a modified version of your code with a minimal bounding box:

\begin{tikzpicture}
\tkzDefPoint(0,0){A}
\tkzDefPoint(2.5,0){B}
\tkzDrawTriangle[two angles = 60 and 60,overlay](A,B)
\tkzGetPoint{C}
\tkzLabelPoint[left](A){$A$}
\tkzLabelPoint[right](B){$B$}
\tkzLabelPoint[above](C){$C$}
\begin{pgfinterruptboundingbox}
\tkzDrawAltitude(A,B)(C)
\tkzGetPoint{D}
\tkzLabelPoint[above right](D){$D$}
\end{pgfinterruptboundingbox}
\tkzMarkRightAngle[color=red](C,D,A)
\tkzLabelAngle[pos=0.5](C,A,B){\small 60\degree}
\tkzLabelAngle[pos=0.5](C,B,A){\small 60\degree}
\tkzLabelSegment[auto](C,D){$s$}
\tkzLabelSegment[auto](A,C){$r$}
\tkzLabelSegment[auto](B,A){18}
\draw (current bounding box.south east) rectangle (current bounding box.north west);
\end{tikzpicture}
\end{center}

That should take care of it for you.

enter image description here

P.S. Would you mind sharing your TikZ code for the other triangles? Thanks!

You must log in to answer this question.

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