Graphics, Figures & TablesWrapfigures in Glossary

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
peng
Posts: 1
Joined: Sun Dec 28, 2014 1:20 am

Wrapfigures in Glossary

Post by peng »

Hi everyone,

i currently fail adding wrap-pictures to a glossary. The glossary contains a register of persons and therefore i want the portrait-photos to appear beside the biography. I tried this like in this example:

Code: Select all

\longnewglossaryentry{kurrein}
{   name= Max Kurrein} {
   \FloatBarrier % avoids floating to other entries.
\begin{wrapfigure}{R}{50mm}
	\centering
	\includegraphics[height = 35mm, angle = 90]{Bilder/kurrein}
	\caption{Max Kurrein}
		\label{kurrein}
\end{wrapfigure}
 ($^\ast 1878 \ \dagger 1967$) Biography.
}
I can compile this code without any errors but in the result the figures are still over or below the text. What's my fault?
I would be very pleased to receive your answers and proposals to this problem.
Peng.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
TikZ book
User avatar
nlct
Posts: 276
Joined: Thu Nov 06, 2008 11:15 am

Wrapfigures in Glossary

Post by nlct »

(I'm sorry this answer is rather late. I only noticed it when I was browsing through the unanswered list. If you've already found a solution, maybe this might help someone else.)

I think in this case it might be easier not to use a float. There are non-floating alternatives where you can use \captionof provided by the capt-of package to insert the caption. If the description text is likely to take up more vertical space than the image height, then you could use something like this example which needs an adjustment to include the caption and label:

Code: Select all

\documentclass{report}

\usepackage{graphicx}

\usepackage{capt-of}
\usepackage[nopostdot,toc]{glossaries}

\makeglossaries

\loadglsentries{example-glossaries-images}

\newcommand{\glsimageareawidth}{50mm}
\newlength\glswidth

\newglossarystyle{images}%
{%
  \setglossarystyle{tree}%
  \renewenvironment{theglossary}{}{}%
  \renewcommand{\glossentry}[2]{%
    \ifglshasfield{useri}{##1}%
    {
      \glswidth=\dimexpr\linewidth-\glsimageareawidth-1em\relax
      \parshape=10
        0pt \glswidth
        0pt \glswidth
        0pt \glswidth
        0pt \glswidth
        0pt \glswidth
        0pt \glswidth
        0pt \glswidth
        0pt \glswidth
        0pt \glswidth
        0pt \linewidth\relax
      \noindent
      \makebox[0pt][l]{%
        \smash{%
         \makebox[\linewidth][r]{%
            \raisebox{-8\baselineskip}
            {\begin{minipage}[b]{\glsimageareawidth}%
             \centering
             \includegraphics[height=6\baselineskip]{\glsentryuseri{##1}}%
             \captionof{figure}{\glsentryname{##1}}\label{fig:##1}
             \end{minipage}
            }%
          }%
        }%
      }%
    }%
    {%
      \noindent
    }%
    \glsentryitem{##1}\textbf{\glstarget{##1}{\glossentryname{##1}}}%
    \space\glossentrydesc{##1}\par
    \indexspace
  }%
  \renewcommand*{\glsgroupskip}{}%
}

\begin{document}

\chapter{Sample}

\forglsentries{\thislabel}{\gls{\thislabel}. }

\printglossary[style=images]

\end{document}
If the description will always take up less vertical space than the image, then there's no need to worry about wrapping the excess lines under the image and you can just have two minipages side by side with the text in one and the image in the other. Something like this:

Code: Select all

\documentclass{article}

\usepackage{graphicx}
\usepackage{capt-of}
\usepackage{glossaries}

\makeglossaries

\longnewglossaryentry{sample}{name={A. Person}}{%
\begin{minipage}[t]{\dimexpr\linewidth-50mm}
($^\ast 1878 \ \dagger 1967$) Biography.
\end{minipage}%
\begin{minipage}[t]{50mm}
\centering
\vtop{%
 \vskip-1ex
 \mbox{\includegraphics[height=35mm]{example-image-10x16}}%
}%
\captionof{figure}{A. Person}
\label{sample}
\par
\end{minipage}%
}

\begin{document}
\gls{sample}

\printglossaries
\end{document}
However, I think it would be better management to store the image filename in one of the user keys and leave the arrangement to the glossary style, as in the first example, where the filename is stored in the user1 field.

Code: Select all

\documentclass{article}

\usepackage{graphicx}
\usepackage{capt-of}
\usepackage{glossaries}

\makeglossaries

\longnewglossaryentry{sample}
{name={A. Person},user1={example-image-10x16}}
{($^\ast 1878 \ \dagger 1967$) Biography.}

\newcommand{\glsimageareawidth}{50mm}

\newglossarystyle{people}{%
 \setglossarystyle{index}% base it on the index style
 \renewcommand*{\glossentry}[2]{%
   \item\glsentryitem{##1}%
   \begin{minipage}[t]{\dimexpr\linewidth-\glsimageareawidth}
     \glstreenamefmt{\glstarget{##1}{\glossentryname{##1}}}% name
     \glstreepredesc % space between name and description
     \glossentrydesc{##1}% description
     \glspostdescription\space ##2% location list
   \end{minipage}%
   \begin{minipage}[t]{\glsimageareawidth}
     \centering
     \vtop{%
      \vskip-1ex
      \mbox{\includegraphics[height=35mm]{\glsentryuseri{##1}}}%
     }%
     \captionof{figure}{\glsentryname{##1}}
     \label{fig:##1}
     \par
   \end{minipage}%
  }%
}

\begin{document}
\gls{sample}

\printglossary[style=people]
\end{document}
This makes it much easier to change the style.

Regards
Nicola Talbot
Post Reply