着色背景

着色背景
\documentclass{book}
\usepackage[a5paper,margin=1in]{geometry}
\usepackage{libertine}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{tikz}
\usetikzlibrary{calc}

\newtheoremstyle{problemstyle}
        {12pt}
        {8ex}
        {}
        {}
        {\bfseries}
        {}
        {0.5em}
        {}
\theoremstyle{problemstyle}
\newtheorem{problem}{Problem}

\begin{document}

\begin{tikzpicture}[remember picture,overlay]
    \fill[blue!10!white] (current page.north west) rectangle ($(current page.north east)+(0,-6cm)$);
\end{tikzpicture}

\begin{problem}
When the polynomial $P(x)$ is divided by $(x-1), (x+1), (x-2)$, it gives the remainders $2, 6, 3$, respectively. Determine:

\begin{displaymath}
\frac{P(x)}{(x-1)(x+1)(x-2)}
\end{displaymath}
\end{problem}


\paragraph*{Solution}
We are given that,
\begin{align*}
P(x)&=(x-1)\cdot Q_1(x)+2\\[1ex]
P(x)&=(x+1)\cdot Q_2(x)+6\\[1ex]
P(x)&=(x-2)\cdot Q_3(x)+3 \tag{1}
\end{align*}

And we know that,
\begin{displaymath}
P(x)=(x-1)(x+1)(x-2)\cdot Q_4(x)+ax^2+bx+c \tag{2}
\end{displaymath}

Plugging in the values from (1) into (2), we have:
\begin{displaymath}
\left.
\begin{aligned}
    P(1)=2&=a+b+c\\[1ex]
    P(-1)=6&=a-b+c\\[1ex]
    P(2)=3&=4a+2b+c
\end{aligned}
\right\}\implies a=1, b=-2, c=3
\end{displaymath}

Thus,
\begin{displaymath}
\frac{P(x)}{(x-1)(x+1)(x-2)}=x^2-2x+3
\end{displaymath}

\end{document}

在此处输入图片描述

我正在尝试将背景颜色从页面左上角(实际整个页面)涂到给定问题右下方的某个空间。在上面的例子中,计算是手动完成的。有什么好方法可以实现它,以便它适用于任何给定长度的内容?

答案1

这个解决方案背后的想法是使用shipout/background钩子并定义一个命令来调用\tikzmark并定义矩形的第二个坐标。(代码肯定需要改进,但我的技能就到此为止了。)

\newcounter{rectmark}
\newcommand{\printrectangle}{\stepcounter{rectmark}
  \gdef\mynode{pic cs:\therectmark}\tikzmark{\therectmark}}
\AddToHook{shipout/background}{%
  \begin{tikzpicture}[remember picture,overlay]
    \fill[blue!10!white] (current page.north west) rectangle 
    ( $ (\mynode) +(\paperwidth,0) $ );
  \end{tikzpicture}
\gdef\mynode{0,0}}

然后在文本中你只需要

\printrectangle

从页面左上角到实际\printrectangle命令的坐标加上一个矩形\paperwidth以到达(实际上是克服)右边距:+(\paperwidth,0)

\gdef\mynode{0,0}重置命令,使之在每个 之后不打印任何内容(实际上是一个零大小的矩形)\printrectangle。如果没有这个命令,所有页面的矩形高度都会等于最后一个 的纵坐标\printrectangle

平均能量损失

\documentclass{book}
\usepackage[a5paper,margin=1in]{geometry}
\usepackage{libertine}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{tikz}
  \usetikzlibrary{calc,tikzmark}

\newtheoremstyle{problemstyle}
        {12pt}
        {8ex}
        {}
        {}
        {\bfseries}
        {}
        {0.5em}
        {}
\theoremstyle{problemstyle}
\newtheorem{problem}{Problem}

\newcounter{rectmark}
\newcommand{\printrectangle}{\stepcounter{rectmark}
  \gdef\mynode{pic cs:\therectmark}\tikzmark{\therectmark}}
\AddToHook{shipout/background}{%
  \begin{tikzpicture}[remember picture,overlay]
    \fill[blue!10!white] (current page.north west) rectangle 
    ( $ (\mynode) +(\paperwidth,0) $ );
  \end{tikzpicture}
\gdef\mynode{0,0}}

\begin{document}


\begin{problem}
When the polynomial $P(x)$ is divided by $(x-1), (x+1), (x-2)$, it gives the remainders $2, 6, 3$, respectively. Determine:

\begin{displaymath}
\frac{P(x)}{(x-1)(x+1)(x-2)}
\end{displaymath}\printrectangle
\end{problem}

\paragraph*{Solution}
We are given that,
\begin{align*}
P(x)&=(x-1)\cdot Q_1(x)+2\\[1ex]
P(x)&=(x+1)\cdot Q_2(x)+6\\[1ex]
P(x)&=(x-2)\cdot Q_3(x)+3 \tag{1}
\end{align*}

And we know that,
\begin{displaymath}
P(x)=(x-1)(x+1)(x-2)\cdot Q_4(x)+ax^2+bx+c \tag{2}
\end{displaymath}

%\clearpage

Plugging in the values from (1) into (2), we have:
\begin{displaymath}
\left.
\begin{aligned}
    P(1)=2&=a+b+c\\[1ex]
    P(-1)=6&=a-b+c\\[1ex]
    P(2)=3&=4a+2b+c
\end{aligned}
\right\}\implies a=1, b=-2, c=3
\end{displaymath}

Thus,
\begin{displaymath}
\frac{P(x)}{(x-1)(x+1)(x-2)}=x^2-2x+3
\end{displaymath}

\begin{problem}
When the polynomial $P(x)$ is divided by $(x-1), (x+1), (x-2)$, it gives the remainders $2, 6, 3$, respectively. Determine:

\begin{displaymath}
\frac{P(x)}{(x-1)(x+1)(x-2)}
\end{displaymath}
\end{problem}

\paragraph*{Solution}
We are given that,
\begin{align*}
P(x)&=(x-1)\cdot Q_1(x)+2\\[1ex]
P(x)&=(x+1)\cdot Q_2(x)+6\\[1ex]
P(x)&=(x-2)\cdot Q_3(x)+3 \tag{1}
\end{align*}

And we know that,
\begin{displaymath}
P(x)=(x-1)(x+1)(x-2)\cdot Q_4(x)+ax^2+bx+c \tag{2}
\end{displaymath}

Plugging in the values from (1) into (2), we have:
\begin{displaymath}
\left.
\begin{aligned}
    P(1)=2&=a+b+c\\[1ex]
    P(-1)=6&=a-b+c\\[1ex]
    P(2)=3&=4a+2b+c
\end{aligned}
\right\}\implies a=1, b=-2, c=3
\end{displaymath}\printrectangle

Thus,
\begin{displaymath}
\frac{P(x)}{(x-1)(x+1)(x-2)}=x^2-2x+3
\end{displaymath}


\end{document}

在此处输入图片描述

答案2

您可以使用eso-pic添加相关宽度和高度的彩色规则:

\documentclass{book}
\usepackage[a5paper,margin=1in]{geometry}
\usepackage{libertine}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{eso-pic}
\newtheoremstyle{problemstyle}
        {12pt}
        {8ex}
        {}
        {}
        {\bfseries}
        {}
        {0.5em}
        {}
\theoremstyle{problemstyle}
\newtheorem{problem}{Problem}

\begin{document}
\AddToShipoutPictureBG*{\AtPageUpperLeft{\color{blue!10}\rule[-1em]{\dimexpr\textwidth + 2em}{1em}}}
\begin{tikzpicture}[remember picture,overlay]
    \fill[blue!10!white] (current page.north west) rectangle ($(current page.north east)+(0,-6cm)$);
\end{tikzpicture}

\begin{problem}
When the polynomial $P(x)$ is divided by $(x-1), (x+1), (x-2)$, it gives the remainders $2, 6, 3$, respectively. Determine:

\begin{displaymath}
\frac{P(x)}{(x-1)(x+1)(x-2)}
\end{displaymath}
\end{problem}


\paragraph*{Solution}
We are given that,
\begin{align*}
P(x)&=(x-1)\cdot Q_1(x)+2\\[1ex]
P(x)&=(x+1)\cdot Q_2(x)+6\\[1ex]
P(x)&=(x-2)\cdot Q_3(x)+3 \tag{1}
\end{align*}

And we know that,
\begin{displaymath}
P(x)=(x-1)(x+1)(x-2)\cdot Q_4(x)+ax^2+bx+c \tag{2}
\end{displaymath}

Plugging in the values from (1) into (2), we have:
\begin{displaymath}
\left.
\begin{aligned}
    P(1)=2&=a+b+c\\[1ex]
    P(-1)=6&=a-b+c\\[1ex]
    P(2)=3&=4a+2b+c
\end{aligned}
\right\}\implies a=1, b=-2, c=3
\end{displaymath}

Thus,
\begin{displaymath}
\frac{P(x)}{(x-1)(x+1)(x-2)}=x^2-2x+3
\end{displaymath}

\end{document} 

在此处输入图片描述

相关内容