8

So I must admit I am way out of my depth and have no idea what I'm doing.

I apologize in advance for a long and complicated question.

I'm trying to build this output:

enter image description here

Which I have successfully (sort of) done.

However, what I really want to do is make a new environment called offset to do this automatically, taking the number of lines occupied by the text as an argument.

I've placed my code to make the environment inside

\newenvironment{offset}
{
Code before content
}
{
Code after content
}

but when I try to use begin{offset} . . . \end{offset} I get the basic framework of my offset environment and the tikz lines, but no text. What (well, how much) am I doing wrong?

Here's the code I've written, with commented blocks to make it easier to test the drawing and placement code inside and outside of the environment call.

\documentclass[final,oneside,11pt]{memoir}
\usepackage{tikz}
\usepackage{calc}
\usepackage{wrapfig}
\usepackage{lipsum}
% \usepackage{showframe}

\newenvironment{offset}
{
    \begin{wrapfigure}[19]{r}[1in]{2in}
        \noindent
        \newlength{\topverticalspacer}
        \setlength{\topverticalspacer}{-\baselineskip-\tabcolsep}
        \vspace*{\topverticalspacer}\\
        \begin{tikzpicture}[remember picture, overlay, inner sep=0pt]
            \node (0, 0) (n1) {};
            \draw[-,line width=1pt] (n1)--(2in, 0);
        \end{tikzpicture}\\
        \newlength{\verticalspacer}
        \setlength{\verticalspacer}{\tabcolsep-\baselineskip}
        \vspace*{\verticalspacer}\\
        \hspace*{\tabcolsep}
        \parbox{1.75in}{\textsf{
        \hspace{-5pt}
}
{
        }}
        \newlength{\bottomspacer}
        \setlength{\bottomspacer}{\baselineskip-\tabcolsep}
        \vspace*{\bottomspacer}\\
        \begin{tikzpicture}[remember picture, overlay, inner sep=0pt]
        \node (0, 0) (n2) {};
        \draw[-,line width=1pt] (n2)--(1in, 0);
    \end{tikzpicture}
    \begin{tikzpicture}[remember picture, overlay, inner sep=0pt]
        \draw[-,line width=1pt] (n1) -- (n2);
    \end{tikzpicture}
    \end{wrapfigure}
}

\begin{document}
    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
    consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    \begin{offset}
    % \begin{wrapfigure}[19]{r}[1in]{2in}
    %   \noindent
    %   \newlength{\topverticalspacer}
    %   \setlength{\topverticalspacer}{-\baselineskip-\tabcolsep}
    %   \vspace*{\topverticalspacer}\\
    %   \begin{tikzpicture}[remember picture, overlay, inner sep=0pt]
    %       \node (0, 0) (n1) {};
    %       \draw[-,line width=1pt] (n1)--(2in, 0);
    %   \end{tikzpicture}\\
    %   \newlength{\verticalspacer}
    %   \setlength{\verticalspacer}{\tabcolsep-\baselineskip}
    %   \vspace*{\verticalspacer}\\
    %   \hspace*{\tabcolsep}
    %   \parbox{1.75in}{\textsf{
    %   \hspace{-5pt}
            Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
            tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
            quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
            consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
            cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
            proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    %   }}
    %   \newlength{\bottomspacer}
    %   \setlength{\bottomspacer}{\baselineskip-\tabcolsep}
    %   \vspace*{\bottomspacer}\\
    %   \begin{tikzpicture}[remember picture, overlay, inner sep=0pt]
    %   \node (0, 0) (n2) {};
    %   \draw[-,line width=1pt] (n2)--(1in, 0);
    % \end{tikzpicture}
    % \begin{tikzpicture}[remember picture, overlay, inner sep=0pt]
    %   \draw[-,line width=1pt] (n1) -- (n2);
    % \end{tikzpicture}
    % \end{wrapfigure}
    \end{offset}
    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
    consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    \lipsum[2-4]
\end{document}

Sorry for the miles-long MWE and for using raw lorem ipsum, I didn't want the paragraph breaks that lipsum inserts.

  • lipsum package has a \lipsum* that does not put in the \par – David Carlisle Nov 17 '14 at 10:28
6

You are missing an awful lot of % at the ends of lines, and

        \parbox{1.75in}{\textsf{
        \hspace{-5pt}
}
{
        }}

Just always makes an empty parbox.

I don't think the tikz code is helping here really it is just complicating things if you just want to draw three lines.

enter image description here

\documentclass[final,oneside,11pt]{memoir}

\usepackage{wrapfig}
\usepackage{lipsum}
% \usepackage{showframe}

\newenvironment{offset}
{%
    \wrapfigure{r}[1in]{2in}%
    \kern-5pt
    \hrule
    \noindent\hbox\bgroup\vrule \kern9.6pt\minipage{\dimexpr2in-10pt\relax}%
    \kern5pt    
}
{%
\par
\kern5pt
\endminipage\egroup
\hrule width 1in
\endwrapfigure
}

\begin{document}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
    consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    \begin{offset}
            Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
            tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
            quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
            consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
            cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
            proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    \end{offset}
    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
    consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    \lipsum[2-4]
\end{document}
  • What do the comments at ends of lines do? I've never heard of a % being required. – Ryan Nov 18 '14 at 22:36
  • 1
    end of line is a space. see tex.stackexchange.com/questions/7453/… – David Carlisle Nov 18 '14 at 22:41
  • Thank you! Coming from Python I've always felt like LaTeX is a little weird about how it handles whitespace. – Ryan Nov 18 '14 at 22:46
  • I used Tikz in my mwe because I'm trying to learn how to make this type of environment, not just how to make this one exactly, because I'm having a lot of trouble researching best practices when things go beyond the basics. Do you know of a definitive resource (besides yourself) that I could read on this topic? I only have 3,723 pages of LaTeX related manuals on my computer and apparently that isn't enough. – Ryan Nov 18 '14 at 22:53
  • @Ryan I know nothing about tikz:-) but clearly you could use the same cutout technique as here but replace the basic \hrule and \vrule by some fancier tikz border with curved corners or whatever. I leave as an exercise for the reader. Honestly you wouldn't believe how little I know about tikz:-0 – David Carlisle Nov 18 '14 at 23:08
6

Several things are going on that are not working for you. First, the new lengths that you're defining should be defined outside of the environment. Secondly, you cannot call \parbox{1.75in}{ in one part of the definition for your new environment and close it in the second part. It's best to use an lrbox for that purpose. Thirdly, wrapfigure needs to be called directly from within the new environment you're defining, not with begin{wrapfigure}. Also, you only really need one tikzpicture to accomplish what you want.

\documentclass[final,oneside,11pt]{memoir}
\usepackage{tikz}
\usetikzlibrary{calc,tikzmark}
\usepackage{calc}
\usepackage{wrapfig}
\usepackage{lipsum}
% \usepackage{showframe}

%% this is where you should define your new lengths
% \newlength{\topverticalspacer}
% \newlength{\verticalspacer}
% \newlength{\bottomspacer}

\newsavebox\myoffsetbox

\newenvironment{offset}
{%%
   \begin{lrbox}{\myoffsetbox}
     \begin{minipage}[t]{1.75in}
       \sffamily
       \noindent
       \hspace{-5pt}%%
}
{%%
     \end{minipage}
   \end{lrbox}%%
   \wrapfigure[19]{r}[1in]{2in}
      \raisebox{\dimexpr\ht\myoffsetbox+\tabcolsep}[0pt][0pt]{\tikzmark{aen1}}%%
      \hspace*{\tabcolsep}%%
      \usebox{\myoffsetbox}%%
      \begin{tikzpicture}[remember picture, overlay, inner sep=0pt]
        \draw[line width=1pt] 
            ($({pic cs:aen1})+(2in,0)$)    -- 
            (pic cs:aen1)                  -- 
            ++ (0,-\dimexpr\ht\myoffsetbox+\dp\myoffsetbox+2\tabcolsep) -- 
            ++ (1in,0);
      \end{tikzpicture}\\
    \endwrapfigure%%
}

\begin{document}
    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
    consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    \begin{offset}
            Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
            tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
            quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
            consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
            cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
            proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    \end{offset}
    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
    consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    \lipsum[2-4]
\end{document}

enter image description here

By using an lrbox, you can measure the width, height, and depth of the offset paragraph to get a better fit for the framing.

UPDATE

Various environments don't play well inside a \newenvironment: this is usually because of how such environments scan ahead to look for their content by searching for their respective \end{<environment name>. That seems to be the case here with \begin{wrapfigure}.

By using the lrbox, I can measure the contents of the text to be offset. Initially, I use \tikzmark to create a mark on the page to reference the beginning of this offset material. I used \raisebox to raise this \tikzmark above the height of the top of the offset material according to its height (\ht\myoffsetbox) and the value of \tabcolsep. I don't want the \raisebox to add any visual white space to the page, so I pass it two optional arguments (I probably don't need both): the first optional argument says to assign the raised box a height of 0pt and the second optional argument says to assign the raised box a depth of 0pt.

The \tikzmark uses its own coordinate system. That means the names of the nodes created by writing \tikzmark{<node name>} are not directly accessible by their name. You need to reference them through the canvas name (coordinate system): pic cs:<node name>. I used the TikZ calc library (not necessary) to facilitate drawing the line across the top of the offset material. The parentheses in ({pic cs:aen1}) are not necessary and could be removed. They're residual from when I was more faithfully following your use of two nodes. I wanted to write (<node name 1>-|<node name 2>): to get the canvas parsed correctly, I needed to write ({pic cs:aen1}-|{pic cs:aen2}).

  • Thanks so much for the thorough answer, but could you explain a little more what you did with the tikzpicture? also, what is the difference with using \wrapfigure—should I be using it that way all the time? – Ryan Nov 17 '14 at 7:42
3

Another alternative is the use of newcommand which is similar to newenvironment.

For references: Link1 Link2

enter image description here

Code

\documentclass[final,oneside,11pt]{memoir}
\usepackage{tikz}
\usepackage{calc}
\usepackage{wrapfig}
\usepackage{lipsum}
% \usepackage{showframe}

\newcommand*{\offset}[1]
{
    \begin{wrapfigure}[19]{r}[1in]{2in}
        \noindent
        \newlength{\topverticalspacer}
        \setlength{\topverticalspacer}{-\baselineskip-\tabcolsep}
        \vspace*{\topverticalspacer}\\
        \begin{tikzpicture}[remember picture, overlay, inner sep=0pt]
            \coordinate (n1) at (0, 0);
            \draw[-,line width=1pt,inner sep=0pt,outer sep=0pt] (n1)--(2in, 0);
        \end{tikzpicture}\\
        \newlength{\verticalspacer}
        \setlength{\verticalspacer}{\tabcolsep-\baselineskip}
        \vspace*{\verticalspacer}\\
        \hspace*{\tabcolsep}
%}
%{
        \parbox{1.75in}{\textsf{
        \hspace{-5pt}
#1}}
        \newlength{\bottomspacer}
        \setlength{\bottomspacer}{\baselineskip-\tabcolsep}
        \vspace*{\bottomspacer}\\
        \begin{tikzpicture}[remember picture, overlay, inner sep=0pt,outer sep=0pt]
        \coordinate  (n2) at (0, 0);
        \draw[-,line width=1pt] (n2)--(1in, 0);
    \end{tikzpicture}
   \begin{tikzpicture}[remember picture, overlay, inner sep=0pt]
        \draw[-,line width=1pt] (n1) -- (n2);
    \end{tikzpicture}
    \end{wrapfigure}
}

\begin{document}
    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
    consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\offset{%
      Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
      tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
      quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
      consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
      cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
      proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
}
    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
    consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    \lipsum[2-4]
\end{document}

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.