1

I have a pchstack environment from the cryptocode package that is slightly too wide to fit within the text width. I want to center it anyway such that it encroaches on both margins. A minimal example would look like this.

\documentclass{article}
\usepackage{cryptocode}
\begin{document}
\begin{center}
  \begin{pchstack}[boxed]
    \makebox[1.2\textwidth]{}
  \end{pchstack}
\end{center}
\end{document}

Now unsurprisingly this does not actually work. There are several answers here for figures and tables that suggest putting the content into a \makebox[0pt]{...} or an adjustbox. However for reasons I don't know, the pchstack environment can't be but in a box. Making any box around it such as

\documentclass{article}
\usepackage{cryptocode}
\begin{document}
\begin{center}
  \makebox[0pt]{
    \begin{pchstack}[boxed]
      \makebox[1.2\textwidth]{}
    \end{pchstack}
  }
\end{center}
\end{document}

leads to pdflatex to complain that

! LaTeX Error: Something's wrong--perhaps a missing \item.

Is there a different way to center something that's too wide or do I need to get the cryptocode package fixed?

Maeher
  • 334

1 Answers1

1

(1) The boxed option places the content in a frame box, thus leaving a space equal to \fboxsep around it (first box).

(2) To cancel the horizontal stretching and make the box fit the width of the text, use the key space (second box, space= 2\fboxsep).

(3) If your content is larger than the width of the text, you can wrap the \pchstack in a minipage and offset it to the left by half the extra size plus the \parindent (last box).

In this simple example, it was done by measuring the width of the longest line, which might not be so simple in a general case, that probably will need a manual correction.

z

\documentclass{article} 
\usepackage[
n,
operators,
advantage,
sets,
adversary,
landau,
probability,
notions,    
logic,
ff,
mm,
primitives,
events,
complexity,
oracles,
asymptotics,
keys]{cryptocode}

\usepackage{showframe}% only for showing the margins \usepackage{xcolor} \renewcommand\fbox{\fcolorbox{red}{white}} % color the frame boxes

\begin{document}

\begin{center} \begin{pchstack}[boxed] % default
\makebox[1.0\textwidth]{default} \end{pchstack} \end{center}

\begin{center} \begin{pchstack}[boxed, space=2\fboxsep]% eliminate the horizontal expansion
\makebox[1.0\textwidth]{space = 2*fboxsep} \end{pchstack} \end{center}

\newlength{\longline} %measure the longest line \settowidth{\longline}{$b \sample \bin (\pk,\sk) \sample \kgen (\secparam) (\state,m_0,m_1) \sample\adv(\secparam, \pk, c) c \sample \enc(\pk,m_b) b' \sample \adv(\secparam, \pk, c, \state) $}

\hspace{\dimexpr -\parindent -\fboxsep + 0.5\linewidth -0.5\longline} \begin{minipage}{\textwidth} \begin{pchstack}[boxed, space=2\fboxsep] \pseudocode[linenumbering]{ b \sample \bin (\pk,\sk) \sample \kgen (\secparam) (\state,m_0,m_1) \sample\adv(\secparam, \pk, c) c \sample \enc(\pk,m_b) b' \sample \adv(\secparam, \pk, c, \state) \ \pcreturn b = b' } \end{pchstack} \end{minipage} \end{document}

Simon Dispa
  • 39,141