# Aligned boxes without exceeding textwidth

I have this:

\newcommand{\bpic}[2]{
\makebox[\textwidth][l]{
\fbox{\makebox[.1\textwidth][r]{\includegraphics[width=20pt]{#1}\hspace*{5pt}}}\fbox{\parbox{.9\textwidth}{#2}\newline}%
}
}

\bpic{resilience.png}{Resilience, in that broken nodes do not compromise the network entirely;}
\bpic{spontaneity.png}{Spontaneity, a feature empowered by the network's capacity to form and heal itself;}
\bpic{decentralization.png}{Decentralization, in the sense that having devices connect directly the need for Internet providers is alleviated;}
\bpic{scale.png}{Scale, as a consequence of the fact that such networks benefit from node density to form a greater number of alternative paths;}
\bpic{throughput.png}{Throughput, an attribute achieved by enabling multiple paths simultaneously to transmit data to a given destination;}
\bpic{balancing.png}{Load balancing, with several alternatives being used to leverage traffic on the network;}
\bpic{costs.png}{Reduced costs of infrastructure, due to the nodes connecting directly, thereby alleviating the need for central authorities.}


That is resulting in this:

All fboxs are there only for the sake of understanding the layout. There a few things wrong with what I want:

• The boxes are exceeding the text width in comparison with the rest of the text. Notice that at the right.

• I wanted the picture and text boxes to be the same height and with the text centered vertically.

• If the text needs more vertically space than what is used by the image, the image below should adjust by being lower––just as with a bullet list.

How can I do this?

Edit

I played around with @marmot's response and got to this, which uses spacing closer to what I need:

To do that I added makebox[40pt][c] to the images:

\begin{tabularx}{\textwidth}{m{40pt}X}
\makebox[40pt][c]{\includegraphics[width=20pt]{resilience.png}} & Resilience, in that broken nodes do not compromise the network entirely;\\
\makebox[40pt][c]{\includegraphics[width=20pt]{spontaneity.png}} & Spontaneity, a feature empowered by the network's capacity to form and heal itself;\\
\makebox[40pt][c]{\includegraphics[width=20pt]{decentralization.png}} & Decentralization, in the sense that having devices connect directly the need for Internet providers is alleviated;\\
\makebox[40pt][c]{\includegraphics[width=20pt]{scale.png}} & Scale, as a consequence of the fact that such networks benefit from node density to form a greater number of alternative paths;\\
\makebox[40pt][c]{\includegraphics[width=20pt]{throughput.png}} & Throughput, an attribute achieved by enabling multiple paths simultaneously to transmit data to a given destination;\\
\makebox[40pt][c]{\includegraphics[width=20pt]{balancing.png}} & Load balancing, with several alternatives being used to leverage traffic on the network;\\
\makebox[40pt][c]{\includegraphics[width=20pt]{costs.png}} & Reduced costs of infrastructure, due to the nodes connecting directly, thereby alleviating the need for central authorities.
\end{tabularx}


In this example the first line is centered with the image, but multiple lines expand the text below without centering the image vertically. @Andrew's response is better with multiple lines (that's the result I'm looking for), but single lines are aligned to the top. I haven't played with the space on this one:

• Have you thought using a tabular for this? (And well, if you add dimensions that exceed the text width, it is perhaps not too surprising that things run over. E.g. tabularx takes care of this.) – user121799 Nov 2 '18 at 0:14

Your desired output looks like a table to me. (If you want to run over page breaks with it, you may want to use longtable instead of tabularx.)

\documentclass{article}
\usepackage{tabularx,graphicx,lipsum}
% \raisebox{-.5\height}{...} from https://tex.stackexchange.com/a/19083/121799
\newcommand{\bpic}[1]{\raisebox{-.5\height}{\includegraphics[width=16pt]{#1}}}
\begin{document}
\lipsum[1]

\noindent
\begin{tabularx}{\textwidth}{m{20pt}X}
\bpic{example-image-a} & Resilience, in that broken nodes do not compromise the
network entirely\\
\bpic{example-image-b} & Spontaneity, a feature empowered by the network's capacity to form and heal itself;\\
\end{tabularx}

\lipsum[2]
\end{document}


Of course, I do not have your figures.

EDIT: I'm confused about your comment. So maybe an even simpler thing will do?

\documentclass{article}
\usepackage{lipsum,graphicx}
\newcommand{\bpic}[1]{\includegraphics[width=16pt]{#1}}
\begin{document}
\lipsum[1]

\begin{itemize}
\item[\bpic{example-image-a}]  Resilience, in that broken nodes do not compromise the
network entirely
\item[\bpic{example-image-b}]  Spontaneity, a feature empowered by the network's capacity to form and heal itself;
\end{itemize}

\lipsum[2]
\end{document}


• Works in terms of not exceeding textwidth and adjusting to the contents of the previous point, but what about centering text vertically? – André Fratelli Nov 2 '18 at 0:36
• @AndréFratelli I am not sure I understand your comment because in the table the texts are centered, aren't they? (For more options see e.g. this post and its answers). Rereading your question, especially "just as with a bullet list.", I added a second option. – user121799 Nov 2 '18 at 0:44
• I mean when the text expands to multiple lines, the image is no longer centered vertically with the text. Please see my edit – André Fratelli Nov 2 '18 at 1:06
• This did it – André Fratelli Nov 2 '18 at 1:08
• Still looking; there's something that still looks weird, but I think it could be because the images are just placeholders. I'll accept your answer and get back to this with final pictures. Thanks. – André Fratelli Nov 2 '18 at 1:12

As marmot suggests, I'd wrap this in a table. In fact, to ensure consistent formatting I would wrap everything into a nice little macro so that you can write your table as

  \ImageTable{
{example-image-a}{Resilience, in that broken nodes ...},
{example-image-b}{Spontaneity, a feature empowered...},
{example-image-c}{Decentralization, in the sense...},
{example-image-a}{Scale, as a consequence of the fact...,
{example-image-b}{Throughput, an attribute achieved...},
{example-image}{Reduced costs of infrastructure, due...}
}


to produce:

So, \ImageTable accepts a comma separated list of pairs that give the image and the corresponding text.

Normally. I would do this using \docsvlist from the etoolbox package but I found it tricky to pass two arguments (the image and the text) through to the \do command (\newcomand\do[2]{...} didn't work). Instead I have used the slightly fancier and scarier looking LaTeX3 package together with the etoolbox package to align the images (this adds a few extra options to the \includegraphics command such as the align=? used below). If you want to tweak the image alignment have a look at the other options available in the package documentation.

Here is the full code:

\documentclass{article}
\usepackage{tabularx}
\usepackage{expl3}
\usepackage{graphbox}
\usepackage{mwe}% for images

\ExplSyntaxOn
\clist_new:N \l_image_table_list
\cs_new_protected:Npn \image_table_row #1 #2 {
\includegraphics[width=20pt, align=t]{#1} & #2\\
}
\cs_new:Npn \ImageTable #1 {%
\noindent
\clist_set:Nn \l_image_table_list {#1}
\begin{tabularx}{\textwidth}{cX}
\clist_map_inline:Nn \l_image_table_list { \image_table_row ##1}
\end{tabularx}
}
\ExplSyntaxOff

\begin{document}

\ImageTable{
{example-image-a}{Resilience, in that broken nodes do not compromise the network entirely;},
{example-image-b}{Spontaneity, a feature empowered by the network's capacity to form and heal itself;},
{example-image-c}{Decentralization, in the sense that having devices connect directly the need for Internet providers is alleviated;},
{example-image-a}{Scale, as a consequence of the fact that such networks benefit from node density to form a greater number of alternative paths;},
{example-image-b}{Throughput, an attribute achieved by enabling multiple paths simultaneously to transmit data to a given destination;},
{example-image-c}{Load balancing, with several alternatives being used to leverage traffic on the network;},
{example-image}{Reduced costs of infrastructure, due to the nodes connecting directly, thereby alleviating the need for central authorities.}
}

\end{document}

• Please see my update. I need to learn this ExplSyntax thing; I never used LaTeX long enough to learn this stuff seriously... – André Fratelli Nov 2 '18 at 1:07
• @AndréFratelli From the comments above it looks like you have solved your problem. The expl3 code looks strange but it works in pretty the same way but with many more features. From the point of view of your question, the line \includegraphics[width=20pt,align=t]{#1} & #2\\  inserts the image and text into a line of the tabularx environment, so you can wrap the \includegraphics commend etc inside \makebox and it will do what you expect. The rest of the code is just what you need to process the comma separated list and then paste the different rows into the tabular environment. – Andrew Nov 2 '18 at 1:34