延长 parbox 高度

延长 parbox 高度

我有以下命令可以在页边距打印文本:

\DeclareRobustCommand{\solutionpage}[1]{\marginpar{%
  \colorbox{lightgray}{\protect\parbox[t]{\dimexpr\marginparwidth-2\fboxsep}{~Proof on page #1}%
}}}

因此文本是“第页证明<数字>“,在一个灰色的框里输入。

如何才能使灰色框在垂直方向上更长?

在此处输入图片描述

左边是现在的 parbox。我想在其顶部和底部添加 3pt。

我怎样才能做到这一点?

这是我的 MWE:

% !TEX TS-program = xelatex
\documentclass[leqno,fleqn]{book}
\usepackage{xcolor}

%% page layout
\usepackage{geometry}
% Main matter page layout
\geometry{%
  asymmetric,
  right=65mm,
  textwidth=125mm,
  marginparsep=7mm,
  marginparwidth=43mm,
  showframe
}

%Change margin par font size to footnotesize:
\makeatletter
\def\@marginparreset{%
  \reset@font
  \footnotesize %<-- Change the font size
  \@setminipage
}
\DeclareRobustCommand{\solutionpage}[1]{\marginpar{%
  \colorbox{lightgray}{\protect\parbox[t]{\dimexpr\marginparwidth-2\fboxsep}{~Proof on page #1}%
}}}

\begin{document}
\ldots which resulted in the following insight: For every prime $p$, there is a prime $p’>p$. In particular, there are infinitely many primes\solutionpage{27}.
\end{document}

在此处输入图片描述

答案1

迷你页面将允许扩展垂直维度

\begin{minipage}[position][height][inner-pos]{width}

该命令\solutionpageXL[<added space>]{<text>}定义了一个可选参数来添加垂直空间,默认值为 0pt。

% !TEX TS-program = xelatex
\documentclass[leqno,fleqn]{book}
\usepackage{xcolor}

%% page layout
\usepackage{geometry}
% Main matter page layout
\geometry{%
    asymmetric,
    right=65mm,
    textwidth=125mm,
    marginparsep=7mm,
    marginparwidth=43mm,
    showframe
}

%Change margin par font size to footnotesize:
\makeatletter
\def\@marginparreset{%
    \reset@font
    \footnotesize %<-- Change the font size
    \@setminipage
}
\DeclareRobustCommand{\solutionpage}[1]{\marginpar{%
        \colorbox{lightgray}{\protect\parbox[t]{\dimexpr\marginparwidth-2\fboxsep}{~Proof on page #1}%
}}}

%****************************** added
\newsavebox{\Mholder}
\newlength{\Dholder}  
\newlength{\addtoholder}    
    
\DeclareRobustCommand{\solutionpageXL}[2][0pt]{\marginpar{%
    \setlength{\addtoholder}{#1}    
    \savebox{\Mholder}{~Proof on page #2}
    \setlength{\Dholder}{\dimexpr\dp\Mholder+\ht\Mholder+\addtoholder}% total height plus addholder 
    \colorbox{lightgray}{\begin{minipage}[c][\Dholder][c]{\dimexpr\marginparwidth-2\fboxsep}\usebox{\Mholder} \end{minipage}%
}}}
%******************************

\begin{document}
    \ldots which resulted in the following insight: For every prime $p$, there is a prime $p’>p$. In particular, there are infinitely many primes\solutionpage{27}.
    
    \ldots which resulted in the following insight: For every prime $p$, there is a prime $p’>p$. In particular, there are infinitely many primes\solutionpageXL[10pt]{27}.
    
    \ldots which resulted in the following insight: For every prime $p$, there is a prime $p’>p$. In particular, there are infinitely many primes\solutionpageXL{27}.       
    
\end{document}

A

相关内容