2

Problem:

I have a problem aligning icons in a description so they match the top of the correspondent text to the right of them.

Minimal Working Example (MWE):

\documentclass{scrreprt}
\usepackage[swedish]{babel}
\usepackage[medfamily,textosf,mathlf,mnsy,amsbb,mixedgreek,minionint,openg,footnotefigures]{MinionPro}
\usepackage[onlytext,medfamily,osf]{MyriadPro}
\usepackage{fontawesome}
\usepackage[shortlabels]{enumitem}
\usepackage{calc}
\usepackage{blindtext}

\begin{document}

\newlength{\introicons}
\setlength{\introicons}{\widthof{\faEnvelopeO}}
\addtolength{\introicons}{\labelsep}
\SetLabelAlign{CenterWithParen}{\makebox[\introicons]{#1}}

\begin{description}[
      itemsep=0.75em, 
      topsep=0pt, 
      parsep=0pt, 
      partopsep=0pt, 
      labelwidth=\introicons, 
      itemindent=0cm, 
      leftmargin=!, 
      rightmargin=0cm, 
      align=CenterWithParen
  ]
  \item[\centering \large \faHtml5] \blindtext[1]
  \item[\centering \faEnvelopeO] \blindtext[1]
  \item[\centering \large \faMobilePhone] \blindtext[1]
\end{description}

\end{document}

Visual example:

enter image description here

Notice how the HTML5 and cell phone icon are not aligned to the top of the text while the e-mail icon is.

2

Here I use scalerel to make the icons the vertical footprint of a capital X. (I also removed \centering from the icon calls, as it seemed superfluous). Note that, because scalerel processes arguments in math mode by default, the use of $ delimiters actually forces the evaluation of the icons in text mode. Instaces of \large were also removed, as scalerel doesn't need them to scale to the specified size.

REVISED SOLUTION (Fixed width, variable height, but top-aligned icons)

\documentclass{scrreprt}
%\usepackage[swedish]{babel}
%\usepackage[medfamily,textosf,mathlf,mnsy,amsbb,mixedgreek,minionint,openg,footnotefigures]{MinionPro}
%\usepackage[onlytext,medfamily,osf]{MyriadPro}
\usepackage{fontawesome}
\usepackage[shortlabels]{enumitem}
\usepackage{calc}
\usepackage{blindtext}
\usepackage{scalerel,graphicx,stackengine}
\def\mydim{15pt}
\newcommand\scalewd[2][\mydim]{%
\fboxsep=\fboxrule%
  \setbox0=\hbox{X}%
  \smash{\belowbaseline[-\ht0]{%
    \rotatebox[origin=right]{-90}{%
      \scaleto{\rotatebox[origin=right]{90}{\belowbaseline[0pt]{#2}}}{#1}%
    }%
  }}%
}
\begin{document}

\newlength{\introicons}
\setlength{\introicons}{\widthof{\faEnvelopeO}}
\addtolength{\introicons}{\labelsep}
\SetLabelAlign{CenterWithParen}{\makebox[\introicons]{#1}}
\begin{description}[
      itemsep=0.75em, 
      topsep=0pt, 
      parsep=0pt, 
      partopsep=0pt, 
      labelwidth=\introicons, 
      itemindent=0cm, 
      leftmargin=!, 
      rightmargin=0cm, 
      align=CenterWithParen
  ]
  \item[\scalewd{\faHtml5}] \blindtext[1]
  \item[\scalewd{\faEnvelopeO}] \blindtext[1]
  \item[\scalewd{\faMobilePhone}] \blindtext[1]
\end{description}

\clearpage\def\mydim{20pt}
\begin{description}[
      itemsep=0.75em, 
      topsep=0pt, 
      parsep=0pt, 
      partopsep=0pt, 
      labelwidth=\introicons, 
      itemindent=0cm, 
      leftmargin=!, 
      rightmargin=0cm, 
      align=CenterWithParen
  ]
  \item[\scalewd{\faHtml5}] \blindtext[1]
  \item[\scalewd{\faEnvelopeO}] \blindtext[1]
  \item[\scalewd{\faMobilePhone}] \blindtext[1]
\end{description}

\end{document}

15pt default icon width

enter image description here

20 pt icon width

enter image description here

ORIGINAL SOLUTION (Fixed height, variable width icons)

\documentclass{scrreprt}
%\usepackage[swedish]{babel}
%\usepackage[medfamily,textosf,mathlf,mnsy,amsbb,mixedgreek,minionint,openg,footnotefigures]{MinionPro}
%\usepackage[onlytext,medfamily,osf]{MyriadPro}
\usepackage{fontawesome}
\usepackage[shortlabels]{enumitem}
\usepackage{calc}
\usepackage{blindtext}
\usepackage{scalerel}
\begin{document}

\newlength{\introicons}
\setlength{\introicons}{\widthof{\faEnvelopeO}}
\addtolength{\introicons}{\labelsep}
\SetLabelAlign{CenterWithParen}{\makebox[\introicons]{#1}}

\begin{description}[
      itemsep=0.75em, 
      topsep=0pt, 
      parsep=0pt, 
      partopsep=0pt, 
      labelwidth=\introicons, 
      itemindent=0cm, 
      leftmargin=!, 
      rightmargin=0cm, 
      align=CenterWithParen
  ]
  \item[\scalerel*{$\faHtml5$}{X}] \blindtext[1]
  \item[\scalerel*{$\faEnvelopeO$}{X}] \blindtext[1]
  \item[\scalerel*{$\faMobilePhone$}{X}] \blindtext[1]
\end{description}

\end{document}

enter image description here

  • This looks like a great solution, with the exception that I would like to scale the icons up. What would I need to add to your code to achieve this? – kexxcream Mar 27 '17 at 14:07
  • @kexxcream what do you mean "scale them up"? Relative to what? For example, you could \scalerel*{$\faHtml5$}{\rule{0pt}{10pt}} – Steven B. Segletes Mar 27 '17 at 14:07
  • Sorry for not being clear, I would like the icons to be the same width as the icon that is the widest. – kexxcream Mar 27 '17 at 14:10
  • @kexxcream So you want the icons of fixed width, but varying height? – Steven B. Segletes Mar 27 '17 at 14:11
  • That is correct. While they will have varying height, they should all be centered relative to each other and also to the top as they currently are. – kexxcream Mar 27 '17 at 14:12

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.