# Showkeys package with very small margins

Hi I am working on an appendix which has very large tables. Since I have these tables , I have narrowed the margins as much as possible so that they fit properly.

I am also using the showkeys package to cross-reference easily the appendix with the main article but since my margins are to narrow, I can't seem to print the complete label. I was wondering, is there a way to print the labels in vertical mode? Here is my minimal working example.

\documentclass[10pt]{article}
\usepackage{geometry}
\geometry{letterpaper}
\geometry{margin=1.5cm}
\usepackage{showkeys}
\usepackage{todonotes}

\begin{document}

\begin{figure}[H]
\caption{Example figure}
\begin{center}
\missingfigure[figwidth=0.7\textwidth]{Testing a long text string}
\end{center}
\end{figure}

\end{document}


This produces me an output like this:

You can see the label cropped at the left side. As you may see, this does not work for me. Is there any way to show the complete label without having to reduce the margins?

Using the url package with as many breaking options turned on as possible and making a fixed width box placed appropriately can help.

\documentclass[10pt]{article}
\usepackage[verbose]{geometry}
\geometry{letterpaper}
\geometry{margin=1.5cm,marginparwidth=1.1cm,marginparsep=0.1cm}
\usepackage{showkeys}
\usepackage{todonotes}

\usepackage[obeyspaces,hyphens,spaces]{url}
\renewcommand*{\showkeyslabelformat}[1]{%
\fbox{\vbox{\hsize=1.1cm\normalfont\small\url{#1}\par}}}

\begin{document}

\begin{figure}[H]
\caption{Example figure}
\begin{center}
\missingfigure[figwidth=0.7\textwidth]{Testing a long text string}
\end{center}
\end{figure}
\end{document}


If you need more break points in the labels then you can try passing such information to the url algorithm. Also making the label ragged-right can help with the spacing:

\documentclass[10pt]{article}
\usepackage[verbose]{geometry}
\geometry{letterpaper}
\geometry{margin=1.5cm,marginparwidth=1.1cm,marginparsep=0.1cm}
\usepackage{showkeys}
\usepackage{todonotes}

\usepackage{ragged2e}
\usepackage[obeyspaces,hyphens,spaces]{url}
\renewcommand*{\showkeyslabelformat}[1]{%
\expandafter\def\expandafter\UrlBreaks\expandafter{\UrlBreaks%  save the current one
\do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j%
\do\k\do\l\do\m\do\n\do\o\do\p\do\q\do\r\do\s\do\t%
\do\u\do\v\do\w\do\x\do\y\do\z\do\A\do\B\do\C\do\D%
\do\E\do\F\do\G\do\H\do\I\do\J\do\K\do\L\do\M\do\N%
\do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V\do\W\do\X%
\do\Y\do\Z}%
\fbox{\vbox{\hsize=1cm\RaggedRight\noindent\normalfont\small\url{#1}\par}}}

\begin{document}

\begin{figure}
\caption{Example figure}
\begin{center}
\missingfigure[figwidth=0.7\textwidth]{Testing a long text string}
\end{center}
$$\label{eq:long-label-without-space} x=y.$$