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:
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?

\captioncommand. So, if you add\caption{}to the first argument of\newenvironment*somewhere after\wrapfigure, it should work. – Jan 07 '18 at 04:24