# Sidebar or sidepar vertical alignment with objects

I am writing a document (memoir) with an extensive use of sidepars. I like a lot that sidepars are aligned vertically according to the line position of the word to which they are attached. My document really requires this feature, because many of the side notes are needed to explain single words as they appear in the text.

But, whenever I have an object, such as a table, I cannot just place my sidepar beside the object, because this way it will appear one line lower than the bottom line of the said object.

Is there a way to have my sidepars aligned to the first line of my object without changing the same-word-line-attach behaviour? (Sidebar seems not to be a good solution).

Thank you, A

\documentclass[a3paper, 14pt, twoside, showtrims]{memoir}

\settrimmedsize{340mm}{210mm}{*}
\settrims{0mm}{86,99mm}
\setlrmarginsandblock{23.3mm}{46.7mm}{*}
\setulmarginsandblock{23.3mm}{54.9mm}{*}
\setmarginnotes{2.8mm}{23.3mm}{1em}
\renewcommand{\sideparfont}{\normalfont\itshape\fontsize{11pt}{13pt \selectfont‌​}
\renewcommand{\footnotesize}{\normalfont\fontsize{11pt}{13pt}\selectfont‌​}
\sideparmargin{outer}

\checkandfixthelayout[nearest]

\begin{document}

\begin{center}

\textit{\Large Table containing several numbers}

\large with no particular meaning.

\end{center}

\begin{center}\begin{tabular}{ | c | c | c | c | c | c | c | c | c | c | c | c | c | c | c | c | }
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
\end{tabular} \end{center} \sidebar{Sidebar}

A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text.

\begin{center}\begin{tabular}{ | c | c | c | c | c | c | c | c | c | c | c | c | c | c | c | c | }
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
\end{tabular} \end{center}\sidepar{Sidepar}

A few lines with random text.\sidebar{Sidebar is aligned at the top of the page.} A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text.\sidepar{Sidepar is 'anchored' to the line to which it is attached.} A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text. A few lines with random text.

\end{document}

• Hi John, and thank you. I am not sure these solutions would work in my case, I also have to import eps pictures from a different source and I can't place a tikz code inside them. Moreover, the margin notes are part of the text, so if include them in tables and pictures they will be lost in case I need to change the pictures (I am keeping any graphic file separate from the text, in fact). – user56153 Oct 13 '14 at 5:15
• \sidepar{\raisebox{5cm}{Sidepar}} will raise it to about the top. If you want precision, compute the height of the tabular using \settoheight and possibly \savebox. – John Kormylo Oct 14 '14 at 4:51
• You can also fool \sidepar into aligning to the top using \raisebox{0pt}[0pt][0pt]{whatever} but then you will need \vspace to avoid overwriting it. – John Kormylo Oct 14 '14 at 5:21

I've found a plain and easy solution:

\documentclass[a3paper, 14pt, twoside, showtrims]{memoir}

\settrimmedsize{340mm}{210mm}{*}
\settrims{0mm}{86,99mm}
\setlrmarginsandblock{23.3mm}{46.7mm}{*}
\setulmarginsandblock{23.3mm}{54.9mm}{*}
\setmarginnotes{2.8mm}{23.3mm}{1em}
\renewcommand{\sideparfont}{\normalfont\itshape\fontsize{11pt}{13pt}\selectfont‌​}
\renewcommand{\footnotesize}{\normalfont\fontsize{11pt}{13pt}\selectfont‌​}
\sideparmargin{outer}

\checkandfixthelayout[nearest]

\begin{document}

\sidepar {Sidepar}

\vspace{-\baselineskip}
\begin{tabular}{ | c | c | c | c | c | c | c | c | c | c | c | c | c | c | c | c | }
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
\end{tabular}

\end{document}


It seems that \sidepar aligns to the bottom, not the baseline. Also, centering seems to have an odd effect on \sidepar (hense \hfil).

\documentclass[a3paper, 14pt, twoside, showtrims]{memoir}

\settrimmedsize{340mm}{210mm}{*}
\settrims{0mm}{86.99mm}
\setlrmarginsandblock{23.3mm}{46.7mm}{*}
\setulmarginsandblock{23.3mm}{54.9mm}{*}
\setmarginnotes{2.8mm}{23.3mm}{1em}
%\renewcommand{\sideparfont}{\normalfont\itshape\fontsize{11pt}{13pt \selectfont‌​}
\renewcommand{\footnotesize}{\normalfont\fontsize{11pt}{13pt}\selectfont‌​}
\sideparmargin{outer}

\checkandfixthelayout[nearest]

\newsavebox{\tempbox}
\newlength{\tempdepth}

\newcommand{\raisesidepar}[2]% #1 = distance, #2 = text
{\sidepar{\raisebox{#1}{\parbox[t]{\marginparwidth}{#2}}}}

\begin{document}

% \sidepar is alligned to bottom, not baseline
\hfill\rule[-1cm]{1pt}{1cm} Baseline is up here.\sidepar{Sidepar}

\hfill\rule[-1cm]{1pt}{1cm} Baseline is up here.%
\sidepar{\raisebox{1cm}{\parbox[t]{\marginparwidth}{Raised content}}}

\hfill\raisebox{0pt}[\height][0pt]{\rule[-1cm]{1pt}{1cm} Baseline is up here.}%
\sidepar{Zero depth}%
\vspace{1cm}

\savebox{\tempbox}{% compute depth
\begin{tabular}[t]{ | c | c | c | c | c | c | c | c | c | c | c | c | c | c | c | c | }
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 \\
\hline
\end{tabular}}%
\settodepth{\tempdepth}{\usebox{\tempbox}}%
% In this case 0pt doesn't work as well
\noindent\hfil\raisebox{0pt}[\height][\baselineskip]{\usebox{\tempbox}}%
\sidepar{Sidepar}%
\vspace{\tempdepth}