仅将 MDFramed 放置在第一页的页眉中

仅将 MDFramed 放置在第一页的页眉中

我想在文档第一页的页眉内放置一个 MDFramed 对象。我似乎无法让它工作。有什么建议吗?

\documentclass[11pt,oneside,a4paper,titlepage]{article}
\usepackage[warnunknown, fasterrors, mathletters]{ucs}
\usepackage[showframe, includehead,top=5mm, margin=.5in]{geometry}
\everymath{\displaystyle}
\usepackage{amsfonts, amsthm, amsmath, amssymb}
\usepackage{mathtools}
\usepackage[mathscr]{euscript}
\usepackage[nointegrals]{wasysym}
\usepackage{physics}  % Lots of useful shortcuts and macros
\usepackage{tikz-cd}
\usepackage{newtxtext,newtxmath}
\usepackage{xcolor}
\usepackage[framemethod=TikZ]{mdframed}
\usetikzlibrary{shadows}
\usepackage{environ}
\usepackage{varwidth}
\newlength{\MyMdframedWidthTweak}%
\NewEnviron{MyMdframed}[1][]{%
    \setlength{\MyMdframedWidthTweak}{\dimexpr%
        +\mdflength{innerleftmargin}
        +\mdflength{innerrightmargin}
        +\mdflength{leftmargin}
        +\mdflength{rightmargin}
        }%
    \savebox0{%
        \begin{varwidth}{\dimexpr\linewidth-\MyMdframedWidthTweak\relax}%
            \BODY
        \end{varwidth}%
    }%
    \begin{mdframed}[
        backgroundcolor=lightgray, 
        shadow=true, 
        shadowsize=4pt,
        roundcorner=5pt,
        userdefinedwidth=\dimexpr\wd0+\MyMdframedWidthTweak\relax, 
        #1]
        \usebox0
    \end{mdframed}
}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[R]{\thepage}


\begin{document}

\begin{figure}
\begin{MyMdframed}[backgroundcolor=gray!20]

{\LARGE\bfseries Calc 2 Study Guide for Final}

\end{MyMdframed}
\end{figure}
\begin{enumerate}
\item $\int \tan{(x)}\sec^2{(x)} \dd{x}$\vspace{6cm}
\item $\int_{1}^{25}\frac{e^{\sqrt{x}}}{\sqrt{x}} \dd{x}$\vspace{6cm}
\item $\int \tan^{-1}{(3x)} \dd{x}$\vspace{6cm}
\pagebreak
\item $\int_{0}^{\pi} x \sin(3x)\dd{x}$\vspace{6cm}
\item $\int x^2\cos{(x)} \dd{x}$\vspace{6cm}

\item $\int \frac{\ln{(x)}}{x^2} \dd{x}$\vspace{6cm}
\item $\int \frac{x}{2}e^{-2x} \dd{x}$\vspace{6cm}
\item $\int 3x^2\ln{(5x)} \dd{x}$\vspace{6cm}
\item $\int \cos^5{(x)} \dd{x}$\vspace{6cm}
\item $\int \sin^2{(x)}\cos^2{(x)} \dd{x}$\vspace{6cm}
\item $\int \frac{\sqrt{x^2-1}}{x^4} \dd{x}$\vspace{6cm}
\item $\int \frac{x^3}{\sqrt{1+x^2}} \dd{x}$\vspace{6cm}
\item $\int \frac{1}{\sqrt{4-x^2}} \dd{x}$\vspace{6cm}
\item $\int \frac{x-4}{x^2-5x+6} \dd{x}$\vspace{6cm}
\item $\int \frac{x}{(x-1)(x^2+9)} \dd{x}$\vspace{6cm}
\item $\int \frac{x^2-2x-1}{(x^2+1)(x-1)^2} \dd{x}$\vspace{6cm}
\item $\int_{2}^{5} \frac{1}{\sqrt{5-x}} \dd{x}$\vspace{6cm}
\item $\int_{4}^{\infty} e^{-\frac{x}{2}} \dd{x}$\vspace{6cm}
\item $\int_{2}^{\infty} \frac{1}{x^3} \dd{x}$\vspace{6cm}

\end{enumerate}

\end{document}

这就是我试图做的事情

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[R]{
\begin{figure}
\begin{MyMdframed}[backgroundcolor=gray!20]

{\LARGE\bfseries Calc 2 Study Guide for Final}

\end{MyMdframed}
\end{figure} 
\thepage}

这样实际的 mdframe 就会出现在文档的标题中。

答案1

您需要消除figure环境,因为这不是旨在浮动,并且还要执行条件\ifnum\thepage=1以确保它仅在第一页输出。

\fancyhead[R]{%
    \ifnum\thepage=1
    \begin{MyMdframed}[backgroundcolor=gray!20]
        {\LARGE\bfseries Calc 2 Study Guide for Final}
    \end{MyMdframed}%
    \fi
    \thepage%
}

在此处输入图片描述

代码:

\documentclass[11pt,oneside,a4paper,titlepage]{article}
\usepackage[warnunknown, fasterrors, mathletters]{ucs}
\usepackage[includehead,top=5mm, margin=.5in, head=1.35cm]{geometry}
\everymath{\displaystyle}
\usepackage{amsfonts, amsthm, amsmath, amssymb}
\usepackage{mathtools}
\usepackage[mathscr]{euscript}
\usepackage[nointegrals]{wasysym}
\usepackage{physics}  % Lots of useful shortcuts and macros
\usepackage{tikz-cd}
\usepackage{newtxtext,newtxmath}
\usepackage{xcolor}
\usepackage[framemethod=TikZ]{mdframed}
\usetikzlibrary{shadows}
\usepackage{environ}
\usepackage{varwidth}
\newlength{\MyMdframedWidthTweak}%
\NewEnviron{MyMdframed}[1][]{%
    \setlength{\MyMdframedWidthTweak}{\dimexpr%
        +\mdflength{innerleftmargin}
        +\mdflength{innerrightmargin}
        +\mdflength{leftmargin}
        +\mdflength{rightmargin}
        }%
    \savebox0{%
        \begin{varwidth}{\dimexpr\linewidth-\MyMdframedWidthTweak\relax}%
            \BODY
        \end{varwidth}%
    }%
    \begin{mdframed}[
        backgroundcolor=lightgray, 
        shadow=true, 
        shadowsize=4pt,
        roundcorner=5pt,
        userdefinedwidth=\dimexpr\wd0+\MyMdframedWidthTweak\relax, 
        #1]
        \usebox0
    \end{mdframed}
}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[R]{%
    \ifnum\thepage=1
    \begin{MyMdframed}[backgroundcolor=gray!20]
        {\LARGE\bfseries Calc 2 Study Guide for Final}
    \end{MyMdframed}%
    \fi
    \thepage%
}
\renewcommand{\headrulewidth}{0pt}%

\begin{document}
%\begin{figure}
%\begin{MyMdframed}[backgroundcolor=gray!20]
%
%{\LARGE\bfseries Calc 2 Study Guide for Final}
%
%\end{MyMdframed}
%\end{figure}
\begin{enumerate}
\item $\int \tan{(x)}\sec^2{(x)} \dd{x}$\vspace{6cm}
\item $\int_{1}^{25}\frac{e^{\sqrt{x}}}{\sqrt{x}} \dd{x}$\vspace{6cm}
\item $\int \tan^{-1}{(3x)} \dd{x}$\vspace{6cm}
\pagebreak
\item $\int_{0}^{\pi} x \sin(3x)\dd{x}$\vspace{6cm}
\item $\int x^2\cos{(x)} \dd{x}$\vspace{6cm}

\item $\int \frac{\ln{(x)}}{x^2} \dd{x}$\vspace{6cm}
\item $\int \frac{x}{2}e^{-2x} \dd{x}$\vspace{6cm}
\item $\int 3x^2\ln{(5x)} \dd{x}$\vspace{6cm}
\item $\int \cos^5{(x)} \dd{x}$\vspace{6cm}
\item $\int \sin^2{(x)}\cos^2{(x)} \dd{x}$\vspace{6cm}
\item $\int \frac{\sqrt{x^2-1}}{x^4} \dd{x}$\vspace{6cm}
\item $\int \frac{x^3}{\sqrt{1+x^2}} \dd{x}$\vspace{6cm}
\item $\int \frac{1}{\sqrt{4-x^2}} \dd{x}$\vspace{6cm}
\item $\int \frac{x-4}{x^2-5x+6} \dd{x}$\vspace{6cm}
\item $\int \frac{x}{(x-1)(x^2+9)} \dd{x}$\vspace{6cm}
\item $\int \frac{x^2-2x-1}{(x^2+1)(x-1)^2} \dd{x}$\vspace{6cm}
\item $\int_{2}^{5} \frac{1}{\sqrt{5-x}} \dd{x}$\vspace{6cm}
\item $\int_{4}^{\infty} e^{-\frac{x}{2}} \dd{x}$\vspace{6cm}
\item $\int_{2}^{\infty} \frac{1}{x^3} \dd{x}$\vspace{6cm}
\end{enumerate}
\end{document}

相关内容