我有这个:
\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.}
结果是:
所有的fbox
s 都只是为了理解布局。我想要的有一些问题:
与其余文本相比,这些框超出了文本宽度。请注意右侧的情况。
我希望图片和文本框具有相同的高度并且文本垂直居中。
如果文本需要的垂直空间比图像所使用的空间大,则下方的图像应该调整得更低——就像项目符号列表一样。
我怎样才能做到这一点?
编辑
我根据 @marmot 的回复进行了尝试,得到了这个,它使用的间距更接近我需要的:
为此,我makebox[40pt][c]
在图像中添加了:
\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}
在此示例中,第一行与图像居中,但多行会扩展下方的文本,而不会使图像垂直居中。@Andrew 的回复是多行效果更好(这是我想要的结果),但单行与顶部对齐。我还没有玩过这个的空间:
答案1
在我看来,您想要的输出看起来像一个表格。(如果您想使用它来跨越分页符,您可能需要使用longtable
而不是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}
当然,我没有你的数据。
编辑:我对您的评论感到困惑。也许更简单的做法可以吗?
\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}
答案2
根据 marmot 的建议,我会将其包装在表格中。事实上,为了确保格式一致,我会将所有内容包装到一个漂亮的小宏中,这样您就可以将表格编写为
\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-c}{Load balancing, with several alternatives...},
{example-image}{Reduced costs of infrastructure, due...}
}
生产:
因此,\ImageTable
接受逗号分隔列表给出图像和相应文本的对。
\docsvlist
通常情况下。我会使用电子工具箱包,但我发现将两个参数(图像和文本)传递给\do
命令很棘手(\newcomand\do[2]{...}
不起作用)。相反,我使用了稍微更花哨和更可怕的LaTeX3包装连同电子工具箱软件包来对齐图像(这会为命令添加一些额外选项,\includegraphics
例如align=?
下面使用的选项)。如果您想调整图像对齐,请查看软件包文档中提供的其他选项。
完整代码如下:
\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}