1

I'd like to place an MDFramed object inside my header only on the first page of the document. I can't seem to get it to work. Any suggestions?

\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}

here is what I'm attempint to do

\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}

so that the actual mdframe will apear in the header of the document.

2
  • Not sure what the desired result is. The MyMdframed title is only on the first page. Commented Dec 2, 2021 at 2:22
  • I just updated it.
    – Ziggy
    Commented Dec 5, 2021 at 2:10

1 Answer 1

1

You need to eliminate the figure environment as this is not intended to float and also do a conditional \ifnum\thepage=1 to enure it is only output in the first page.

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

enter image description here

Code:

\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}

Not the answer you're looking for? Browse other questions tagged .