2

I have the following environment to display a sidebar:

\newcommand{\dummy}{}

\newenvironment*{lsidebar}[2][0.5]
{
    \renewcommand{\dummy}{#1}

    \wrapfigure{l}{#1\textwidth}
        \rule{#1\textwidth}{1pt}

        \rule{#1\textwidth}{18pt}

        \vspace{-18pt}
        \centerline{\textcolor{white}{#2}}

        \vspace{5pt}
        \footnotesize
        \leftskip=5pt
        \rightskip=5pt
        \setlength{\parskip}{0.2cm}
        \setlength{\parindent}{0pt}

}
{
        \leftskip=0pt
        \rightskip=0pt
        \setlength{\parindent}{0pt}
        \rule{\dummy\textwidth}{1pt}
        \rule[.19in]{\dummy\textwidth}{2.5pt}
    \endwrapfigure
}

I use the environment like this:

\begin{lsidebar}{Example Sidebar}
    \label{sb:Example}

    An example sidebar.
\end{lsidebar}

Refer to sidebar \nameref*{sb:Example}.

It renders how I want it to. However, the label does not resolve as expected when using \nameref*{sb:Example}. Instead of displaying the sidebar's title, it displays the chapter title:

enter image description here

Here is a complete repro:

\documentclass{book}

\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{hyperref}
\usepackage{color}

\newcommand{\dummy}{}

\newenvironment*{lsidebar}[2][0.5]
{
    \renewcommand{\dummy}{#1}

    \wrapfigure{l}{#1\textwidth}
        \rule{#1\textwidth}{1pt}

        \rule{#1\textwidth}{18pt}

        \vspace{-18pt}
        \centerline{\textcolor{white}{#2}}

        \vspace{5pt}
        \footnotesize
        \leftskip=5pt
        \rightskip=5pt
        \setlength{\parskip}{0.2cm}
        \setlength{\parindent}{0pt}

}
{
        \leftskip=0pt
        \rightskip=0pt
        \setlength{\parindent}{0pt}
        \rule{\dummy\textwidth}{1pt}
        \rule[.19in]{\dummy\textwidth}{2.5pt}
    \endwrapfigure
}

\begin{document}

\chapter{First}
\label{ch:First}

\begin{lsidebar}{Example Sidebar}
    \label{sb:Example}

    An example sidebar.
\end{lsidebar}

Refer to sidebar \nameref*{sb:Example}.

\end{document}

Can anyone tell me how to resolve the name/title of the sidebar instead of the chapter?

Kent Boogaart
  • 664
  • 4
  • 15
  • Referencing figures only works with a \caption command. So, if you add \caption{} to the first argument of \newenvironment* somewhere after \wrapfigure, it should work. –  Jan 07 '18 at 04:24
  • @marmot thanks for that! I'm a LaTeX newb, in case it isn't obvious. If you want to add that as an answer, I'll happily accept. – Kent Boogaart Jan 07 '18 at 04:30
  • Thanks, but this question already has an answer here. I forgot to add the link to my comment above, sorry. –  Jan 07 '18 at 04:32

0 Answers0