3

How would you modify the following code so that the words "First shape", "Second shape", and "third shape" are vertically aligned?

Thank you!

matchstick

\documentclass[11pt,twoside]{book}
\usepackage[
paperwidth=7in,
paperheight=10in,
inner=0.75in,   % inside margin (gutter) for binding
outer=0.5in,    % outside margin
top=0.75in,     % top margin
bottom=0.75in   % bottom margin
]{geometry}
%
% Packages
\usepackage[utf8]{inputenc}
\usepackage{amsmath, amssymb, amsfonts} % math symbols
\usepackage{geometry}
\usepackage{graphicx} % figures
\usepackage{tikz} % drawings

% Page layout
%
\usepackage{pgfplots}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{pgfplots}
\usepackage{array}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
\textbf{23} A pattern of shapes is created with matchsticks.\\[0.15cm]
\hspace*{6mm}The first three shapes are shown below.\\
\begin{center}
$\begin{array}[b]{lcc}
\text{First shape}
&
\quad
&
\begin{tikzpicture}
%left
\node[rotate around={+60:(-0.2,-0.5)}] (image) at (-0.2,-0.5) {\includegraphics[]{Stick.png}};
\node[rotate around={+120:(-0.35,+0.15)}] (image) at (-0.35,+0.15) {\includegraphics[]{Stick.png}};
%center
\node[] (image) at (0,0) {\includegraphics[]{Stick.png}};
%right
\node[rotate around={-60:(0.2,-0.5)}] (image) at (0.2,-0.5) {\includegraphics[]{Stick.png}};
\node[rotate around={-120:(0.35,+0.15)}] (image) at (0.35,+0.15) {\includegraphics[]{Stick.png}};
\end{tikzpicture}
\\
\text{Second shape}
&
\quad
&
\begin{tikzpicture}
%left
\node[rotate around={+60:(-0.2,-0.5)}] (image) at (-0.2,-0.5) {\includegraphics[]{Stick.png}};
\node[rotate around={+120:(-0.35,+0.15)}] (image) at (-0.35,+0.15) {\includegraphics[]{Stick.png}};
%center
\node[] (image) at (0,0) {\includegraphics[]{Stick.png}};
%right
\node[rotate around={-60:(0.2,-0.5)}] (image) at (0.2,-0.5) {\includegraphics[]{Stick.png}};
\node[rotate around={-120:(0.35,+0.15)}] (image) at (0.35,+0.15) {\includegraphics[]{Stick.png}};
%
\node[xshift=1.6cm] (image) at (0,0) {\includegraphics[]{Stick.png}};
%right
\node[xshift=1.6cm,rotate around={-60:(0.2,-0.5)}] (image) at (0.2,-0.5) {\includegraphics[]{Stick.png}};
\node[xshift=1.6cm,rotate around={-120:(0.35,+0.15)}] (image) at (0.35,+0.15) {\includegraphics[]{Stick.png}};
\end{tikzpicture}
\\
\text{Third shape}
&
\quad
&
\begin{tikzpicture}
%left
\node[rotate around={+60:(-0.2,-0.5)}] (image) at (-0.2,-0.5) {\includegraphics[]{Stick.png}};
\node[rotate around={+120:(-0.35,+0.15)}] (image) at (-0.35,+0.15) {\includegraphics[]{Stick.png}};
%center
\node[] (image) at (0,0) {\includegraphics[]{Stick.png}};
%right
\node[rotate around={-60:(0.2,-0.5)}] (image) at (0.2,-0.5) {\includegraphics[]{Stick.png}};
\node[rotate around={-120:(0.35,+0.15)}] (image) at (0.35,+0.15) {\includegraphics[]{Stick.png}};
%
\node[xshift=1.6cm] (image) at (0,0) {\includegraphics[]{Stick.png}};
%right
\node[xshift=1.6cm,rotate around={-60:(0.2,-0.5)}] (image) at (0.2,-0.5) {\includegraphics[]{Stick.png}};
\node[xshift=1.6cm,rotate around={-120:(0.35,+0.15)}] (image) at (0.35,+0.15) {\includegraphics[]{Stick.png}};
%
\node[xshift=3.2cm] (image) at (0,0) {\includegraphics[]{Stick.png}};
%right
\node[xshift=3.2cm,rotate around={-60:(0.2,-0.5)}] (image) at (0.2,-0.5) {\includegraphics[]{Stick.png}};
\node[xshift=3.2cm,rotate around={-120:(0.35,+0.15)}] (image) at (0.35,+0.15) {\includegraphics[]{Stick.png}};
\end{tikzpicture}
\quad
\end{array}$
\end{center}
\text{}\\[-0.3cm]
\\
\hspace*{6mm}Find an expression for the number of matchsticks used for the $n$th shape.
\end{document}
2
  • 3
    Please remove ALL packages not needed to show your problem. Thank you Commented 2 days ago
  • 2
    Thank you for posting a working example! At the same time, much of your code does not seem to be relevant to the question you're asking here. Please limit the example to only the code required for your issue to appear. You can have a look at this guide for how to prune your code for this purpose. Commented 2 days ago

3 Answers 3

2

You could let the adjustbox package do the vertical alignment for you:

\documentclass{book}

\usepackage{tikz}
\usepackage{adjustbox}
\usepackage{amsmath}

\begin{document}

$\begin{array}[b]{lcc}
\text{First shape}
&
\quad
&
\begin{adjustbox}{valign=c}
\begin{tikzpicture}
%left
\node[rotate around={+60:(-0.2,-0.5)}] (image) at (-0.2,-0.5) {\includegraphics[]{Stick.png}};
\node[rotate around={+120:(-0.35,+0.15)}] (image) at (-0.35,+0.15) {\includegraphics[]{Stick.png}};
%center
\node[] (image) at (0,0) {\includegraphics[]{Stick.png}};
%right
\node[rotate around={-60:(0.2,-0.5)}] (image) at (0.2,-0.5) {\includegraphics[]{Stick.png}};
\node[rotate around={-120:(0.35,+0.15)}] (image) at (0.35,+0.15) {\includegraphics[]{Stick.png}};
\end{tikzpicture}%
\end{adjustbox}%
\\
\end{array}$

\end{document}

enter image description here

2
  • Worked beautifully! Thank you! Commented yesterday
  • @WillKim You're welcome! Commented yesterday
4

I would suggest using tabular. With tabular, all labels are placed in the first column and therefore appear strictly one under another, while baseline=(current bounding box.center) ensures that all three drawings are aligned vertically in the same way relative to the text.

Note that since I do not have the matchstick image, I added its drawing in the preamble and introduced the command \onehouse to simplify the code. You are free to do whatever you like with this code, including completely ignoring it.:)

\documentclass{article}
\usepackage{tikz}

% "Matchstick" defined as a pic
\tikzset{
  pics/stick/.style={
    code={
      % wooden stick
      \fill[brown] (-0.45,-0.05) rectangle (0.45,0.05);
      % match head
      \fill[red]   (-0.45,0) circle[radius=0.08];
    }
  }
}

% One "house" made of five matchsticks
\newcommand{\onehouse}{%
  \pic[rotate=60]   at (-0.2,-0.5)  {stick};
  \pic[rotate=120]  at (-0.35,0.15) {stick};
  \pic              at (0,0)        {stick};
  \pic[rotate=-60]  at (0.2,-0.5)   {stick};
  \pic[rotate=-120] at (0.35,0.15)  {stick};
}

\begin{document}

\begin{center}
\begin{tabular}{@{}l@{\qquad}l@{}}
First shape &
  \begin{tikzpicture}[baseline=(current bounding box.center)]
    \onehouse
  \end{tikzpicture}
\\[1ex]
Second shape &
  \begin{tikzpicture}[baseline=(current bounding box.center)]
    \onehouse
    \begin{scope}[xshift=1.6cm] % shift for the second house
      \onehouse
    \end{scope}
  \end{tikzpicture}
\\[1ex]
Third shape &
  \begin{tikzpicture}[baseline=(current bounding box.center)]
    \onehouse
    \begin{scope}[xshift=1.6cm] % second house
      \onehouse
    \end{scope}
    \begin{scope}[xshift=3.2cm] % third house
      \onehouse
    \end{scope}
  \end{tikzpicture}
\end{tabular}
\end{center}

\end{document}

enter image description here

2
  • 1
    So I have misunderstood. Commented 2 days ago
  • 1
    @Sebastiano To be honest, I am not entirely sure that I have fully and correctly understood the OP either. But let’s see what they say. Commented 2 days ago
3

I would have been quicker using bclogo, taking even the top part of the matchstick and camouflaging it.

\documentclass{article}
\usepackage{lipsum}    
\usepackage[tikz]{bclogo}
\usepackage[dvipsnames]{xcolor}
\newcommand{\bcimg}{\hspace{-.11cm}\includegraphics[width=\logowidth]{fia.png}}
\definecolor{fia}{RGB}{226, 193, 112}
\begin{document}

\begin{bclogo}[
    couleur=white,
    couleurTexte=black,
    couleurBarre=fia,
    couleurBord=white,
    epBarre=4.7, % <- --------- increase Barre
    logo=\bcimg
]{Mon Titre}
\lipsum[4]
\end{bclogo}

\end{document}

enter image description here

The image of the superior part of the matchstick: https://imgur.com/a/CUVy0Ip

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.