0

I want to position certain elements exactly in the corners of my page. With research, textblock seemed to be what I needed.

Here is a working example of that, before wrapfigure caused problems:

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

Here is how it renders. This is exactly as intended. (There is extra vertical padding due to the -1 y-coordinate argument to the textblock environment, but otherwise the LEFT and RIGHT boxes are tightly in their respective corners.)

enter image description here

If we comment out the \myblocks invocations and uncomment \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 

enter image description here

Then these float-out tables also behave as intended, with text wrapping around them.

However, if I uncomment both of these, they both break.

\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 

Here's how it renders:

enter image description here

There are multiple problems:

  • there is extra whitespace to the left of LEFT on both pages, it needs to be tight,

  • the float-out table for "Alpha" is entirely missing,

  • the float-out table for "Beta" is above the section heading, tight to the right-hand margin (as if it's inside the textblock)

I tried reversing the order of \myblock and \mybox invocations:

\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 

This also renders incorrectly:

enter image description here

The LEFT whitespace is gone but now neither table floats out to the edge nor lets the "lorem ipsum" text wrap around it. Moreover there is a warning in the compiler output:

Package wrapfig Warning: wrapfigure used inside a conflicting environment on in put line 43.

Package wrapfig Warning: Stationary wrapfigure forced to float on input line 44

I don't understand these messages.

The intended end goal for this is that the "LEFT" and "RIGHT" placeholders will be generated to conform to the section heading. In other words, I will end up write something like this

\newcommand{\mysection}[1]
{
    \chapter{\gettitle{#1}}
    \drawcornerfeatures{#1}
}

\mysection{Alpha}
\begin{wrapfigure}{o}{0.3\textwidth}
    ...
\end{wrapfigure}
Lorem ipsum ...

This means the code which generates the "LEFT" and "RIGHT" features must come before the float-out table or the lorem ipsum text. In other words, the warning-emitting final example above is the correct order of events, and it although it draws the corners correctly, I need the tables to float out.

How can I get both of these effects to work together?

1

Just add \par at the end of the definition of \mybox and use thiscommand after \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} 

enter image description here

  • Thank you. Two follow-ups, if you'd be so kind: why does \par make a difference, and what's with that "conflicting environment" warning? The warning is still there. – spraff Jan 4 '18 at 19:20
  • @spraff: Actually, if you test \mybox without \par, followed by several consecutive paragraphs, you'll see it is placed near the 2nd paragraph. If you add a blank line between \mybox and the 1st paragraph, it works fine. In other words, it doesn't consider, for some reason, that the true 1st paragraph is the 2nd unless you add a blank line. Remember wrapfig must be placed before a paragraph, so the simplest was to add a \par in the definition of \mybox. – Bernard Jan 4 '18 at 19:59
  • @spraff: The conflicting environment problem is solved: it was due to wrapfig not liking to be near a list environment, and the flushright environment is implemented as a trivlist. So I replaced it with a group including the \raggedleft directive. Also, while I was at it, I added \noindent at the end of the definition of \myboxsince I think it looks nicer. Please test the new code. – Bernard Jan 4 '18 at 20:03
  • \raggedleft and \noindent seem to work fine, thank you. – spraff Jan 4 '18 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.