6

How do I distribute the following picture in such a way that

  1. it is printed on two A4 landscape
  2. 1cm in the centre repeat itself (that is, the right most cm on the first page is equal to the left most cm on the second page)
\documentclass{article}
\usepackage[a4paper,margin=.5cm,landscape]{geometry}
\usepackage{etex}
\usepackage{tikz}
\usepackage{musixtex}
\def\threedp#1{\pgfmathparse{#1}\expandafter\Threedp\pgfmathresult0000@}
\def\Threedp#1.#2#3#4#5@{#1.#2#3#4}
\begin{document}
\pgfdeclarelayer{blacknotes}
\pgfsetlayers{main,blacknotes}
\tikzset{tight fit/.style={inner sep=0pt, outer sep=0pt}}

\begin{tikzpicture}
\def\lastnotenodename{clefs}
\node [text width=1cm, tight fit] (clefs) at (0,0) {
    \begin{music}
        \instrumentnumber{1}
        \instrumentnumber{2}
        \nostartrule        
        \setstaffs1{1}
        \setstaffs2{1}  
        \setclef1{\bass}
        \setclef2{\treble}                                  
        \startextract
        \hskip2.0\elemskip
        \zendextract
    \end{music}
};

\foreach \note [
    evaluate={
        \n=int(mod(\note-1, 12));
        \octave=int((\note+8)/12);
        \t=int(floor((\note-1)/12)*7-7);
        \notename={"A","","B","C","","D","","E","F","","G",""}[\n];
        \tonicsolfa={"la","","si","so","","r\`e","","mi","fa","","sol",""}[\n];
        \blacknote={0,1,0,0,1,0,1,0,0,1,0,1}[\n];
        \frequency=(2^((\note-49)/12))*440;}
] in {1,...,88}{

    \ifnum\octave>3
        \tikzset{extract anchor/.style={anchor=south west, at=(\lastnotenodename.south east)}}
    \else
        \tikzset{extract anchor/.style={anchor=north west, at=(\lastnotenodename.north east)}}
    \fi
    \ifnum\blacknote=0
        \edef\notenodename{\notename_\octave}
        \node (\notenodename) [tight fit,text width=1cm, extract anchor/.try]  {%           
            \begin{music}
                \instrumentnumber{1}
                \instrumentnumber{2}
                \nostartrule        
                \setstaffs1{1}
                \setstaffs2{1}  
                \setclefsymbol1{\empty}
                \setclefsymbol2{\empty}     
                \setclef1{\bass}
                \setclef2{\treble}                      
                \startextract
                \transpose\t
                \hskip-1.5\elemskip         
                \ifnum\octave>3
                    \ifnum\octave>4
                        \Notes \nextinstrument \ql{\notename} \en       
                    \else
                        \Notes \nextinstrument \qu{\notename} \en                       
                    \fi
                \else
                    \ifnum\octave>2
                        \Notes \ql{\notename} \en
                    \else
                        \Notes \qu{\notename} \en
                    \fi
                \fi
                \zendextract
            \end{music}
        };
        \xdef\lastnotenodename{\notenodename}       
        \node [anchor=base] (sol-fa)  at (\notenodename |- 0,-3) {\tonicsolfa$_\octave$};

        \draw (\notenodename.south west |- 0,-4) rectangle ++(1, -4);
        \node [rotate=90, font=\footnotesize, anchor=east] 
            at (\notenodename.north |- 0,-4) {\threedp\frequency};
        \node [font=\footnotesize, anchor=south]  
            at (\notenodename.south |- 0,-8) {\note};
        \node [font=\footnotesize, anchor=south] 
            at (\notenodename.south |- 0,-8.5)  {\notename$_\octave$};
        \draw (\notenodename.south west |- sol-fa.south) 
            rectangle (\notenodename.south east |- 0,1.125); %0.125 by trial and error
    \else
        \begin{pgfonlayer}{blacknotes}
        \fill ([xshift=-0.25cm]\lastnotenodename.north east |- 0,-4) rectangle ++(0.5, -2.5);
        \node  [rotate=90, text=white, font=\footnotesize, anchor=east]
            at (\lastnotenodename.north east |- 0,-4) {\threedp\frequency};
        \end{pgfonlayer}
    \fi
}
\node [rotate=90] at (0,-6) {Fr\`equency (Hz)};
\end{tikzpicture}

\end{document}

At the moment only one page is printed with a part of the picture: page

The code is from Range of a piano: keyboard vs staves .

12

Using collectbox and trimclip we can realize what you want in a more general way, that is, for any box. I added some optional arguments for additional clipping (e.g. for dealing with content that exceeds its bounding box).

\documentclass{scrbook}

\usepackage{mwe}
\usepackage{trimclip}
\usepackage{xparse}

\makeatletter
  \newcommand\doublepagesplitoverlap{1cm}
  \NewDocumentCommand\doublepagesplit{
    O{\doublepagesplitoverlap}    % overlap
    D||{0pt}  % clip left
    D||{#2}   % clip right
    D!!{0pt}  % clip top
    D!!{#4}   % clip bottom
  }{%
    \cleardoubleevenpage\leavevmode\vfil
    \flushright
    \collectbox{%
      \@doublepagesplit
        {#2}{#4}%
        {\dimexpr (\width - #1) / 2\relax}%
        {#4}{#5}%
    }%
  }
  \newcommand\@doublepagesplit[5]{%
    \clipbox{{#1} {#2} {#3} {#5}}{\BOXCONTENT}%
    \clearpage\leavevmode\vfil
    \flushleft
    \clipbox{{#3} {#2} {#4} {#5}}{\BOXCONTENT}%
    \clearpage
  }
\makeatother

\begin{document}

\doublepagesplit{\includegraphics{example-image}\relax}

\end{document}

split example image

Putting this into your document (and copying KOMA-Script's \cleardoubleevenpage) we get

\documentclass{article}

\usepackage[a4paper,margin=.5cm,landscape]{geometry}
\usepackage{tikz}
\usepackage{musixtex}
\usepackage{trimclip}
\usepackage{xparse}

\def\threedp#1{\pgfmathparse{#1}\expandafter\Threedp\pgfmathresult0000@}
\def\Threedp#1.#2#3#4#5@{#1.#2#3#4}

\makeatletter
  \newcommand*\cleardoubleevenpage{%
    \clearpage
    \if@twoside\ifodd\c@page
        \hbox{}\newpage\if@twocolumn\hbox{}\newpage\fi
    \fi\fi
  }
  \newcommand\doublepagesplitoverlap{1cm}
  \NewDocumentCommand\doublepagesplit{
    O{\doublepagesplitoverlap}    % overlap
    D||{0pt}  % clip left
    D||{#2}   % clip right
    D!!{0pt}  % clip top
    D!!{#4}   % clip bottom
  }{%
    \cleardoubleevenpage\leavevmode\vfil
    \flushright
    \collectbox{%
      \@doublepagesplit
        {#2}{#4}%
        {\dimexpr (\width - #1) / 2\relax}%
        {#4}{#5}%
    }%
  }
  \newcommand\@doublepagesplit[5]{%
    \clipbox{{#1} {#2} {#3} {#5}}{\BOXCONTENT}%
    \clearpage\leavevmode\vfil
    \flushleft
    \clipbox{{#3} {#2} {#4} {#5}}{\BOXCONTENT}%
    \clearpage
  }
\makeatother

\pgfdeclarelayer{blacknotes}
\pgfsetlayers{main,blacknotes}
\tikzset{tight fit/.style={inner sep=0pt, outer sep=0pt}}

\begin{document}

\doublepagesplit|-.5cm|{%
\begin{tikzpicture}
\def\lastnotenodename{clefs}
\node [text width=1cm, tight fit] (clefs) at (0,0) {
    \begin{music}
        \instrumentnumber{1}
        \instrumentnumber{2}
        \nostartrule        
        \setstaffs1{1}
        \setstaffs2{1}  
        \setclef1{\bass}
        \setclef2{\treble}                                  
        \startextract
        \hskip2.0\elemskip
        \zendextract
    \end{music}
};

\foreach \note [
    evaluate={
        \n=int(mod(\note-1, 12));
        \octave=int((\note+8)/12);
        \t=int(floor((\note-1)/12)*7-7);
        \notename={"A","","B","C","","D","","E","F","","G",""}[\n];
        \tonicsolfa={"la","","si","so","","r\`e","","mi","fa","","sol",""}[\n];
        \blacknote={0,1,0,0,1,0,1,0,0,1,0,1}[\n];
        \frequency=(2^((\note-49)/12))*440;}
] in {1,...,88}{

    \ifnum\octave>3
        \tikzset{extract anchor/.style={anchor=south west, at=(\lastnotenodename.south east)}}
    \else
        \tikzset{extract anchor/.style={anchor=north west, at=(\lastnotenodename.north east)}}
    \fi
    \ifnum\blacknote=0
        \edef\notenodename{\notename_\octave}
        \node (\notenodename) [tight fit,text width=1cm, extract anchor/.try]  {%           
            \begin{music}
                \instrumentnumber{1}
                \instrumentnumber{2}
                \nostartrule        
                \setstaffs1{1}
                \setstaffs2{1}  
                \setclefsymbol1{\empty}
                \setclefsymbol2{\empty}     
                \setclef1{\bass}
                \setclef2{\treble}                      
                \startextract
                \transpose\t
                \hskip-1.5\elemskip         
                \ifnum\octave>3
                    \ifnum\octave>4
                        \Notes \nextinstrument \ql{\notename} \en       
                    \else
                        \Notes \nextinstrument \qu{\notename} \en                       
                    \fi
                \else
                    \ifnum\octave>2
                        \Notes \ql{\notename} \en
                    \else
                        \Notes \qu{\notename} \en
                    \fi
                \fi
                \zendextract
            \end{music}
        };
        \xdef\lastnotenodename{\notenodename}       
        \node [anchor=base] (sol-fa)  at (\notenodename |- 0,-3) {\tonicsolfa$_\octave$};

        \draw (\notenodename.south west |- 0,-4) rectangle ++(1, -4);
        \node [rotate=90, font=\footnotesize, anchor=east] 
            at (\notenodename.north |- 0,-4) {\threedp\frequency};
        \node [font=\footnotesize, anchor=south]  
            at (\notenodename.south |- 0,-8) {\note};
        \node [font=\footnotesize, anchor=south] 
            at (\notenodename.south |- 0,-8.5)  {\notename$_\octave$};
        \draw (\notenodename.south west |- sol-fa.south) 
            rectangle (\notenodename.south east |- 0,1.125); %0.125 by trial and error
    \else
        \begin{pgfonlayer}{blacknotes}
        \fill ([xshift=-0.25cm]\lastnotenodename.north east |- 0,-4) rectangle ++(0.5, -2.5);
        \node  [rotate=90, text=white, font=\footnotesize, anchor=east]
            at (\lastnotenodename.north east |- 0,-4) {\threedp\frequency};
        \end{pgfonlayer}
    \fi
}
\node [rotate=90] at (0,-6) {Fr\`equency (Hz)};
\end{tikzpicture}
}

\end{document}

split piano keyboard

  • Thank you very much, this is what I needed. Have you seen that the keys on the left have been cut in one half? – PeptideChain Jul 25 at 11:52
  • 1
    @PeptideChain I had not. This happens because the clefs exceed the bounding box of your TikZ picture. In your case, the easiest fix is probably to replace \clipbox with \trimbox. The keyboard will be shown all the way to the edge of the paper then. If I guess your use case correctly (namely, just printing it out) This should not matter too much. – schtandard Jul 25 at 12:10
  • @PeptideChain I added some optional arguments that enable you to deal with the issue directly. – schtandard Jul 25 at 12:54

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.