General ⇒ Adding icons to left of enumerate items
Adding icons to left of enumerate items
For example, if I wanted to have one happy face to the left of item 4 and then two happy faces to the left of item 8?
Thanks.
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
Adding icons to left of enumerate items
Code: Select all
\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{wasysym}
\usepackage{url}
\begin{document}
\newcommand{\IconCry}{\includegraphics[width=1em]{icon_cry.jpg}}
\newcommand{\IconRazz}{\includegraphics[width=1em]{icon_razz.jpg}}
\newcommand{\IconEWink}{\includegraphics[width=1em]{icon_e_wink.jpg}}
\begin{itemize}
\item[\IconCry] An item of a list
\item Other item, this one uses the default label
\item[\IconRazz] A smiley
\item Again the default label
\item[\IconEWink] Is it clear now?
\item[\frownie] This face comes from the \textsf{wasysym} package
\item[\smiley] This one too.
\end{itemize}
This also works with \texttt{enumerate} instead of \texttt{itemize}.
Check this document for a large list of predefined symbols:\\ \small
\url{www.ctan.org/tex-archive/info/ symbols/comprehensive/symbols-a4.pdf}
\end{document}

- Attachments
-
- icon_e_wink.jpg (1.75 KiB) Viewed 14290 times
-
- icon_razz.jpg (1.07 KiB) Viewed 14291 times
-
- icon_cry.jpg (1.74 KiB) Viewed 14291 times
Re: Adding icons to left of enumerate items
I want the normal numbering in an enumerate.
1.
2.
3.
etc.
But to the left of some of the numbers I would like to sometimes put a symbol. For example:
1.
2.
*3.
4.
**5.
etc.
with the numbers lining up like normal over each other and the symbols appearing in the margin to the left.
I want to use this for example to label certain homework problems I am creating as harder or easier, while keeping the same numbering scheme.
Adding icons to left of enumerate items
Code: Select all
\documentclass[12pt]{article}
\usepackage{graphicx}
\newcommand{\IconCry}{\includegraphics[width=1em]{icon_cry.jpg}}
\newcommand{\IconRazz}{\includegraphics[width=1em]{icon_razz.jpg}}
\newlength{\SmileysLength}
\setlength{\SmileysLength}{\labelwidth}\addtolength{\SmileysLength}{\labelsep}
\newcommand{\hard}{\hspace*{-\SmileysLength}\makebox[0pt][r]{\IconCry}%
\hspace*{\SmileysLength}}
\newcommand{\easy}{\hspace*{-\SmileysLength}\makebox[0pt][r]{\IconRazz}%
\hspace*{\SmileysLength}}
\begin{document}
List of problems:
\begin{enumerate}
\item A normal problem
\item \easy An easy problem
\item \hard This one is hard
\item This is normal
\item This one too
\item \easy Again an easy problem
\item \hard We conclude with a hard one
\end{enumerate}
\end{document}
Re: Adding icons to left of enumerate items
A brief description of the steps should be okay, if you don't mind.
Adding icons to left of enumerate items
When LaTeX finds something like
Code: Select all
\item \easy Statement of an easy problem
Now, the length \SmileysLength is equal to \labelwidth+\labelsep, which are two of the several parameters which control lists. \labelwidth is the space reserved for writing the label of each item, whereas \labelsep is the separation distance between the label and the first character of the item text.
Finally, it is important to understand the use of zero-width boxes, since they allow to achieve some special effects, as in this case. The \makebox and \framebox commands have an optional argument to tell LaTeX which is the width of the resulting box. A command like \makebox[2cm]{text} constructs a 2cm wide box, independently of the length of the text which contains. If the text is short, there will be white space filling the box, but if the text is long, it will extend out of the box, superimposed to the surrounding text. Both commands have a second optional argument to control to where the contained text should be adjusted: r (right), l (left) or c (centered, default). Depending on this parameter, for short text, the filling blank space is on the right, on the left or on both sides of the box. For long text, it marks the side of the box through which the text will expand out.
Re: Adding icons to left of enumerate items
Why is there an asterisk after \hspace?
And why is there a % in your \hard and \easy commands?
And since you jump to the left exactly the distance of the label and labelsep and then right justify, why isn't the smiley directly up against the number? is there automatic character spacing added by latex?
Thanks again, you are really, really helping me learn about latex here.
Oh, and playing around with it I came up with one additional question.
I have a graphic icon that sits a little "high" on the line. I would like to be able to lower it's lower edge a little bit below the baseline for that line. Is there a way to do this easily?
Adding icons to left of enumerate items
The \hspace* space command always leaves space, even in places where \hspace does not, as the beginning of lines. Compile this to see it:dmt wrote:Why is there an asterisk after \hspace?
Code: Select all
Text text text. \\
\hspace{2cm}More text text text.\\
\hspace*{2cm}Even more text text text.
When LaTeX finds the % symbol stops processing characters in the same line of the source file. This fact allows to intersperse the code with comments. But it is also helpful to divide a long line of code into several ones without introducing spurious blank spaces. Take into account that the spaces or the carriage return at the end of a line in the source file produces a space in the document. Check what happens if you remove % in the definition of \hard: the text of the corresponding list items will not be properly aligned, due to the extra space written after the smiley.dmt wrote:And why is there a % in your \hard and \easy commands?
The label of each item is typeset right justified in a box of length \labelwidth. If the label does not completely fill the box, you see blank space on its left. However, if you have, say, 100 problems, things look different. Compile this:dmt wrote:And since you jump to the left exactly the distance of the label and labelsep and then right justify, why isn't the smiley directly up against the number? is there automatic character spacing added by latex?
Code: Select all
\begin{enumerate}
\setcounter{enumi}{100}
\item A normal problem
\item \easy An easy problem
\item \hard This one is hard
\end{enumerate}
You can use the \raisebox command. It has two mandatory arguments: the length you want move up or down a text and the text itself. Compare Text with \raisebox{5pt}{Text} and \raisebox{-5pt}{Text}. Suppose that you want to raise down the "razz" icon by 15pt. It would suffice the following redefinition of \IconRazz:dmt wrote:I have a graphic icon that sits a little "high" on the line. I would like to be able to lower it's lower edge a little bit below the baseline for that line. Is there a way to do this easily?
Code: Select all
\newcommand{\IconRazz}{\raisebox{-15pt}{\includegraphics[width=1em]{icon_razz.jpg}}}