3

Playing around with this post I tried to use framed boxes on a doublesided document but there is a strange issue.

Why left boxes are not centered in (outer)margin like right ones ?

enter image description here

Here is a minimal example:

\setuppagenumbering[alternative=doublesided]


\setuplayout[width=fit,
            height=270mm,
            rightmargin=60mm,
            rightmargindistance=5mm]


\defineframedtext[sideboxframed][frame=on,
                                framecolor=black,
                                rulethickness=1pt,
                                width=5cm,
                                offset=overlay,
                                align=normal]


\defineuserdataalternative[enumeration:sidebox][renderingsetup=sidenote:sidebox]


\startsetups[sidenote:sidebox]
\margindata[inouter]{
    \startsideboxframed
    \getinlineuserdata
    \stopsideboxframed
}
\stopsetups


\defineuserdata [sidebox] [alternative=enumeration:sidebox]




\starttext


\dorecurse{2}{\input knuth}
\startuserdata[sidebox]
    \input ward
\stopuserdata
\dorecurse{2}{\input knuth}
\startuserdata[sidebox]
    \input ward
\stopuserdata
\dorecurse{2}{\input knuth}
\startuserdata[sidebox]
    \input ward
\stopuserdata
\dorecurse{2}{\input knuth}
\startuserdata[sidebox]
    \input ward
\stopuserdata


\stoptext
  • Can you provide a minimal example. – Wolfgang Schuster May 5 at 15:06
  • When you add \showframe to your example you can see the frame if left aligned in the margin area on both sides. – Wolfgang Schuster May 5 at 15:54
  • Oh, you are right! Then, is there a way to center them on both sides without having to deal with margins distances, edges and stuff like that? – dpi May 5 at 16:04
5

The problem in your example is how you set the value for the right margin of the page. When you use width=fit ConTeXt calculates the space with the values of the rightmargin and rightmargindistance which leaves no space between the margin area and the page border.

\setuppapersize[A4][A4,oversized]

\setuplayout
  [width=fit,
   rightmargin=60mm,
   rightmargindistance=5mm,
   location=middle]

\showframe

\starttext
\page[dummy]
\stoptext

enter image description here

When you use now \inouter (or \margindata[inouter]) to put text in the margin area the content is aligned with the left margin of the area which leaves a space at the right side.

\setuppapersize[A4][A4,oversized]

\setuplayout
  [width=fit,
   rightmargin=60mm,
   rightmargindistance=5mm,
   location=middle]

\showframe

\starttext
\inouter{\inframed[width=5cm]{Margin text}}
\input knuth
\stoptext

enter image description here

To avoid this you have to use a different method to change the value of the right margin. To do this you have to use width=middle for \setuplayout and set the space for the right side with the cutspace key. The value for cutspace should be larger than rightmargin and rightmargindistance combined to leave space between the margin area and the page border.

\setuppapersize[A4][A4,oversized]

\setuplayout
  [width=middle,
   cutspace=60mm,
   rightmargin=50mm,
   rightmargindistance=5mm,
   location=middle]

\showframe

\starttext
\page[dummy]
\stoptext

enter image description here

To ensure the distance between the frame and the text block is the same on odd and even pages set the width of both to the same value. There is also no need for an extra frame because margindata provides a frame mechanism which can be accessed with marginframed but it's the best to create a new instance where you set your own style.

\setuppagenumbering [alternative=doublesided]

\setuplayout
  [              width=middle, % textwidth = paperwidth - backspace - cutspace
              cutspace=60mm,
           rightmargin=50mm,
   rightmargindistance=5mm]

\definemargindata   [sidebox] [inouter]
\definemarginframed [sidebox] [inouter]

\setupmarginframed
  [sidebox]
  [frame=on,
   rulethickness=1pt,
   width=5cm,
   offset=overlay,
   framecolor=black,
   align={normal,verytolerant}]


\defineuserdataalternative [enumeration:sidebox] [renderingsetup=sidenote:sidebox]

\showframe

\startsetups[sidenote:sidebox]
    \margindata[sidebox]{\getinlineuserdata}
\stopsetups

\defineuserdata [sidebox] [alternative=enumeration:sidebox]

\starttext

\startbuffer
    \dorecurse{2}{\input knuth}
    \startuserdata[sidebox]
        \input ward
    \stopuserdata
\stopbuffer

\dorecurse{4}{\getbuffer}

\stoptext
| improve this answer | |

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.