6

I'm currently trying to define a list of icons/images which will take the size of the line height and be vertically aligned to the lines. This list is basically a list to explain what are these icons about. The example below is what I want to achieve, and is taken from the Apple iOS documentation website.enter image description here

I grabbed the images from there, but these are a bit larger than the actual line height. Specifying and including the images as it without resizing them should thus produce a rendered version with each image a bit greater than expected. What is weird is that this isn't what I got as rendered version: some images appear way greater than others. I know each image differs lightly in size from the others (e.g.: 26x30, 30x30, 36x32, etc.) but AFAIK this couldn't be reason and explain that issue.

enter image description here

I thought that reducing the size of each image (and keep their ratio) using the size of the line would be enough, like described here. Unfortunately, since this is not possible to determine the height of the line we are currently in as it depends on a bunch of factors: space between lines and font size, etc.

I then decided I should just scale each image using a value that could suit the rendered version using trial and error, but this value isn't automatically computed and as soon I change the size of the text, I need to recompute the value manually. Not really efficient. I got a some better result, but I've still the problem some images appear really smaller than others.

enter image description here

To solve the centering problem I thought to the command \vcenter but I've some issues with it: it requires me to be in math mode and the rest of the line appears outside the page borders.

enter image description here

The ugly code I've for now:

\begin{itemize}
    \item $\vcenter{\includegraphics[scale=0.5]{fig_xcode_inspector_file}} Some text$
    \item $\vcenter{\includegraphics[scale=0.5]{fig_xcode_inspector_quick_help}} yet some text$
    \item $\vcenter{\includegraphics[scale=0.5]{fig_xcode_inspector_identity}} some text$
    \item $\vcenter{\includegraphics[scale=0.5]{fig_xcode_inspector_attributes}} some text$
    \item $\vcenter{\includegraphics[scale=0.5]{fig_xcode_inspector_size}} some text $
    \item $\vcenter{\includegraphics[scale=0.5]{fig_xcode_inspector_connections}} some text $
\end{itemize}

Any help helping me to solve this issue is welcome.

  • Why scale? do you know they have the same size to begin with? Again I think the adjustbox package can help a lot. – daleif Mar 17 '15 at 10:50
  • @daleif I need to scale them because they are a bit too large to fit the line height. And like I said, they aren't all exactly the same size, so why are you writing "they have the same size to begin with"? And I followed your advices, I'm using the 'adjustbox` package for other purpose than this question. – wget Mar 17 '15 at 11:01
  • @daleif I looked the package adjustbox more in details, and even if I have the values maxheight, I still need to compute the height value manually :-/ – wget Mar 17 '15 at 11:06
  • Why, what is wrong with just height=1em? – daleif Mar 17 '15 at 11:12
6

Like this?

\documentclass{article}
\usepackage[export]{adjustbox}
\usepackage{enumitem}
\begin{document}
  \begin{itemize}
    \item \includegraphics[valign=b,height=\fontcharht\font`X]{example-image} Some text
    \item \includegraphics[valign=b,height=\fontcharht\font`X]{example-image-a} Some text
    \item \includegraphics[valign=b,height=\fontcharht\font`X]{logo} Some text
    \item \includegraphics[valign=b,height=\fontcharht\font`X]{pecemblem} Some text    
\end{itemize}
\end{document}

enter image description here

  • Is \fontcharht e-TeX? It seems like it isn't available in Knuth TeX. – Henri Menke Mar 17 '15 at 11:12
  • @HenriMenke Yes, it is eTeX. but you can get around it in this case, if need be. – yo' Mar 17 '15 at 11:15
  • Yes, as I'm using LaTeX with the xelatex TeX engine, this isn't compiling. If you have a pure LaTeX/TeX variant, that would be cool ;-) – wget Mar 17 '15 at 11:58
  • @wget This will compile with xelatex for me. I am using miktex 2.9 duly updated. – user11232 Mar 17 '15 at 13:24
  • @HarishKumar Indeed, the problem was on my side. And it indeed comes from eTeX, but the XeTeX engine understands this command. This is quite weird as XeTeX is said to be built on TeX + LaTeX, not on eTeX. IIUC, the eTeX command \fontcharht calculates the height of the font letter defined with \font, but I don't understand well what `X is about and what it does exactly. – wget Mar 17 '15 at 13:39
4

If you'd wanted center alignment (as your \vcenter suggested) then I'd recommend adjustbox as Harish showed, but here I think you are better with the default baseline alignment. I'd just do

enter image description here

\documentclass{article}
\usepackage{graphicx}
\begin{document}
  \begin{itemize}
    \item \includegraphics[height=.7em]{example-image} Some text
    \item \includegraphics[height=.7em]{example-image-a} Some text
    \item \includegraphics[height=.7em]{logo} Some text
    \item \includegraphics[height=.7em]{example-image-b} Some text    
\end{itemize}
\end{document}
  • Thanks for your solution. But as wanted to have the icons a bit taller, I defined 1em instead of 0.7. By using this value, we clearly see the alignment isn't correct. I surrounded \includegraphics by adjustbox like advised and defined the valign key to m, which should correctly align the icon vertically, but in practise this isn't. I tried to redefine the value of \adjboxvcenter like described in the doc, but didn't got any positive result. I don't know how to redefine that macro :-/ I'm always getting its value printed on the page and not taken into account. – wget Mar 17 '15 at 12:06
2

I don't think \vcenter is what you are looking for. A good estimate for the line height is given by \fontdimen22\textfont2+1ex which is the height of the math axis plus the height of the letter x. The $\null\mathsurround=0pt$ is there to initialise the math fonts in TeX, else you will get an error message that there are only 7 fontdimens in nullfont.

\documentclass{article}
\usepackage{graphicx}
\newcommand\icon[2]{%
  $\null\mathsurround=0pt$%
  \includegraphics[height=\dimexpr\fontdimen22\textfont2+1ex\relax]{#1}
  \textbf{#2.}\space
}
\begin{document}
\begin{itemize}
\item \icon{example-image-a}{File} Some text
\end{itemize}
\end{document}

enter image description here

1

Here I set the icon in place of the bullet, though that can be changed by removing it from the [ ] brackets. Also, here, I set the icons to the vertical extent of a cap X, though I comment out an alternative approach where the height may be explicitly specified, with the icon sitting on the baseline of the specified height.

\documentclass{article}
\usepackage{graphicx,scalerel}
\usepackage{enumitem}
\def\seticon#1{%
  \scalerel*{\includegraphics{#1}}{X}% SCALES TO SIZE OF CAP X
%  \scaleto{\includegraphics{#1}}{2ex}% SPECIFY THE HEIGHT OF THE SCALE
}
\begin{document}
  \begin{itemize}
    \item [\seticon{example-image}] Some text
    \item [\seticon{example-image-a}] Some text
    \item [\seticon{ARL_Logo_March2012_BlackGold}] Some text
    \item [\seticon{sbs2}] Some text    
\end{itemize}
\end{document}

enter image description here

Here's the alternate form, setting the icons to 2ex height on the baseline.

enter image description here

1

If you can find and use a suitable icon font (here I've used Font Awesome, which requires XeLaTeX or LuaLaTeX), you can drop the images entirely and the scaling with font size problem is handled automatically. Other benefits are higher-quality symbols, infinite scalability, and smaller PDF file size.

\documentclass{article}
\usepackage{fontawesome}
\newcommand{\myitem}[2]{\item #1 {\bfseries\sffamily #2}}

\def\testlist{%
\begin{itemize}
  \myitem{\faFile}{File.} Specify general information about the storyboard.
  \myitem{\faQuestionSign}{Quick Help.} Get useful documentation about an object.
  \myitem{\faThumbnailsList}{Identity.} Specify a custom class for your object 
    and define its accessibility attributes.
\end{itemize}
}

\begin{document}\sffamily
{\testlist\par}

{\huge\testlist\par}

\end{document}

enter image description here

  • Thanks for the hint, but unfortunately, I must use the icons provided on the Apple website or use my own, I have been unable to find font that could suit the one provided by Xcode. – wget Mar 17 '15 at 11:56

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.