我想将某些元素精确地放置在页面的角落。经过研究,textblock
似乎这就是我所需要的。
wrapfigure
这是之前导致问题的一个工作示例:
\documentclass[a4paper,10pt,openany,twoside]{scrbook}
\usepackage{wrapfig}
\usepackage[absolute]{textpos}
\setlength{\TPHorizModule}{\paperwidth}
\setlength{\TPVertModule}{\paperheight}
\newcommand{\myblocks}
{
\begin{textblock}{1}[0,-1](0,0)
{\huge LEFT LEFT LEFT}
\end{textblock}
\begin{flushright}
\begin{textblock}{1}[0,-1](0,0)
{\huge RIGHT RIGHT RIGHT}
\end{textblock}
\end{flushright}
}
\newcommand{\mybox}
{
\begin{wrapfigure}{o}{0.3\textwidth}
\subsection*{TEST}
TEST WRAP FIGURE
\begin{tabular}{|lrl|}
\hline
a & b & c \\
a & b & c \\
a & b & c \\
\hline
\end{tabular}
\end{wrapfigure}
}
\begin{document}
\chapter{blank page}
\chapter{Alpha}
%\mybox
\myblocks
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
\chapter{Beta}
%\mybox
\myblocks
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
\end{document}
-1
以下是它的渲染效果。这与预期完全一致。(由于的 y 坐标参数,因此存在额外的垂直填充textblock environment
,但除此之外LEFT
和RIGHT
框都紧紧地位于各自的角落。)
如果我们注释掉\myblocks
调用并取消注释\mybox
......
\chapter{Alpha}
\mybox
%\myblocks
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
\chapter{Beta}
\mybox
%\myblocks
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
然后这些浮动表格也会按预期运行,文本环绕它们。
但是,如果我取消对这两个的注释,它们都会中断。
\chapter{Alpha}
\mybox
\myblocks
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
\chapter{Beta}
\mybox
\myblocks
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
它的渲染方式如下:
存在多个问题:
两页左侧都有多余的空白
LEFT
,需要紧凑一些,“Alpha” 的浮动表完全缺失,
“Beta”的浮动表是多于章节标题紧靠右边距(就像在里面一样
textblock
)
\myblock
我尝试颠倒和调用的顺序\mybox
:
\chapter{Alpha}
\myblocks
\mybox
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
\chapter{Beta}
\myblocks
\mybox
lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
这也会导致错误渲染:
空白LEFT
消失了,但现在表格既不会浮到边缘,也不会让“lorem ipsum”文本环绕它。此外,编译器输出中还有一个警告:
包 wrapfig 警告:在输入行 43 中的冲突环境中使用了 wrapfigure。
软件包 wrapfig 警告:固定的 wrapfigure 强制浮动在输入行 44 上
我不明白这些信息。
这样做的最终目标是生成“LEFT”和“RIGHT”占位符以符合章节标题。换句话说,我最终会写出类似这样的内容
\newcommand{\mysection}[1]
{
\chapter{\gettitle{#1}}
\drawcornerfeatures{#1}
}
\mysection{Alpha}
\begin{wrapfigure}{o}{0.3\textwidth}
...
\end{wrapfigure}
Lorem ipsum ...
这意味着生成“左”和“右”特征的代码必须位于浮动表或 lorem ipsum 文本之前。换句话说,上面发出警告的最后示例是事件的正确顺序,尽管它正确地绘制了角落,但我需要表格浮动。
我怎样才能使这两种效果一起发挥作用?
答案1
\par
只需在定义末尾添加\mybox
并使用此命令后 \myblocks
:
\documentclass[a4paper,10pt,openany,twoside]{scrbook}
\usepackage{wrapfig}
\usepackage[absolute]{textpos}
\setlength{\TPHorizModule}{\paperwidth}
\setlength{\TPVertModule}{\paperheight}
\newcommand{\myblocks}
{
\begin{textblock}{1}[0,-1](0,0)
{\huge LEFT LEFT LEFT}
\end{textblock}
{\raggedleft\begin{textblock}{1}[0,-1](0,0)
{\huge RIGHT RIGHT RIGHT}
\end{textblock}}
}
\newcommand{\mybox}
{%
\begin{wrapfigure}{o}{0.3\textwidth}
\subsection*{TEST}
TEST WRAP FIGURE
\begin{tabular}{|lrl|}
\hline
a & b & c \\
a & b & c \\
a & b & c \\
\hline
\end{tabular}
\end{wrapfigure}\par\noindent
}
\begin{document}
\chapter{blank page}
\chapter{Alpha}
\myblocks
\mybox
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipisc-ing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrum.
\chapter{Beta}
\myblocks
\mybox%
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipisc-ing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrum.
\end{document}