3

I combine multiple pdf files into one file, using tcbraster and \tcbincludepdf (from the package tcolorbox). I have a problem with the output. This is the MWE process:

I first use this file (file name=1.tex) to generate a single page pdf file:

\documentclass[a4paper]{article}
\usepackage{geometry}
\usepackage[final]{pdfpages}
\usepackage{graphicx}
\pagestyle{empty}
\usepackage[skins,raster]{tcolorbox}
\begin{document}
\centering
\scalebox{30}{1}\newpage
\end{document}

I then use this file (file name=2.tex) to generate a 2 page pdf file:

\documentclass[a4paper]{article}
\usepackage{geometry}
\usepackage[final]{pdfpages}
\usepackage{graphicx}
\pagestyle{empty}
\usepackage[skins,raster]{tcolorbox}
\begin{document}
\centering
\scalebox{30}{2}\newpage
\scalebox{30}{2}\newpage
\end{document}

I now use this file (file name=MWE.tex)to combine all pdf files using a custom tcolorbox raster:

\documentclass[a4paper]{article}
\usepackage{geometry}
\usepackage[final]{pdfpages}
\usepackage{graphicx}
\pagestyle{empty}
\usepackage[skins,raster,most]{tcolorbox}
\newtcolorbox[
auto counter,
list inside=box,
number format=\arabic,
]{file}[2][]{
enhanced,width=15cm,height=20cm,
breakable,bottom=5mm,
colback=white,
colframe=white,
fonttitle=\bfseries,
coltitle=black,
title=File
\thetcbcounter:\quad#2,#1}
%
\begin{document}
\begin{file}{One Page}
\begin{tcbraster}[%
    raster columns=1,enhanced,
    colframe = white,
   raster equal skip=0pt,
    colback = blue!20!white,width=15cm,height=20cm,
    colbacktitle = black!50,
    fonttitle = \small\ttfamily,
    boxsep = 0pt,
    toptitle = 1mm,
    bottomtitle = 1mm,
    center title,
    graphics pages = {1},
 title = {MWE\ [\imagepage]}]
\tcbincludepdf{1.pdf}
\end{tcbraster}
\end{file}
%
\begin{file}{Two Pages}
\begin{tcbraster}[%
    raster columns=1,enhanced,
    colframe = white,
   raster equal skip=0pt,
    colback = blue!20!white,width=15cm,height=20cm,
    colbacktitle = black!50,
    fonttitle = \small\ttfamily,
    boxsep = 0pt,
    toptitle = 1mm,
    bottomtitle = 1mm,
    center title,
    graphics pages = {1,2},
 title = {MWE\ [\imagepage]}]
\tcbincludepdf{2.pdf}
\end{tcbraster}
\end{file}
\end{document}

The problem however, that this code generates difference is heights of the boxes. The second file has one page with a title, and another page without a title. Screenshot: enter image description here I want to be able to flush all boxes to the bottom of the page.

Anyone has an idea how do it?

3
  • 4
    There is no difference in height of the boxes. The problem is that you insert a title before the first box (with file title) and the vertical alignment between pages is different. Unless you use a fixed placement for every page ( with eso-pic or similar packages) I don't know how to solve the problem. – Ignasi Jan 5 at 12:00
  • Could you show me how to do it? – Morzen Jan 5 at 17:12
  • It's the file environment. Why do you need it? btw, if you add \vspace after the \begin{file} you pull the first box up. you could use the raster number n option to try and move the second maybe? – Elad Den Jan 6 at 16:42
2
+50

This is a proposal for (at this moment) a partial solution.

From my point of view, the main problem is the use of an external tcolorbox called file to add a title for the inner tcbraster. This external title moves the first box of the inner tcbraster and all other boxes from the same file look misplaced. Appart of this title, the file environment also uses an internal counter and add information for a table of boxes.

What is proposed here is to forget the file environment and use a simple tcbraster but adding the external title with an overlay option for the first box of every raster. The advantage of this solution is that the overlayed title is not considered on the box placement and all boxes look aligned in every page. The main problem is that the counter and table of boxes are lost until more work is done. But as this partial solution is valid only when the file title is the only text added around tcbrasters, I need to know if my considerations are valid before trying to do this extra work.

In order to apply an overlay only to the first box a little changes has been applied to original use of tcbincludepdf. It seems that options used to apply a particulat style to a certain box into a raster (like raster number x) don't work when tcbincludepdf is used. Therefore an alternative solution has been used. In this case tcbincludepdf has been replaced by a foreach construction inside the raster with command tcbincludegraphics. The list used in foreach corresponds to pages to be included inside the raster.

\documentclass[a4paper]{article}
\usepackage{geometry}
\usepackage[final]{pdfpages}
%\usepackage{graphicx}
\pagestyle{empty}
\usepackage[skins,raster,most]{tcolorbox}

\newtcolorbox[
auto counter,
list inside=box,
number format=\arabic,
]{file}[2][]{
enhanced,width=15cm,height=20cm,
breakable,bottom=5mm,
colback=white,
colframe=white,
fonttitle=\bfseries,
coltitle=black,
title=File
\thetcbcounter:\quad#2,#1}

\tcbset{%
myrasterstyle/.style={%
    enhanced,
    raster columns=1,
   raster equal skip=0pt,
    colframe = white,
   colback = blue!20!white, width=15cm,height=20cm,
   colbacktitle = black!50,
   fonttitle = \small\ttfamily,
   boxsep = 0pt,
   toptitle = 1mm,
   bottomtitle = 1mm,
   center title,
%   graphics pages = {1},
    title = {MWE\ [\imagepage]},
    raster number 1/.style={overlay={\node[anchor=south west, font=\bfseries] at (frame.north west) {File: #1};}}
}
}

\begin{document}
\begin{tcbraster}[myrasterstyle={One Page}]
\foreach \i in {1}{
\tcbincludegraphics[graphics options={page=\i}]{1.pdf}}
\end{tcbraster}

\begin{tcbraster}[myrasterstyle={Two Pages}]
\foreach \i in {1,2}{
\tcbincludegraphics[graphics options={page=\i}]{2.pdf}}
\end{tcbraster}
\end{document}

enter image description here

Update: tcbraster replaced by a foreach loop

This is a second alternative which I hope solve all problems. This solution consists in using a foreach loop to build independent tcolorboxes instead of using a tcbraster. Every box is formed by an external box (for the title) and an inner tcbincludepdf box with the desired style. But two kind of external boxes are used, one with initialization options (to build a table of contents and enumerate all files) which prints the title and a second one whiout initizlization options and with a \phantom title. This way box boxes will have the same space and inner boxes will be aligned on each page.

\documentclass[a4paper]{article}
\usepackage{geometry}
%\usepackage[final]{pdfpages}
\pagestyle{empty}
\usepackage[skins,raster,most]{tcolorbox}

\newtcolorbox[
    auto counter,
    list inside=box,
    number format=\arabic,
    ]{file}[2][]{%
    enhanced,
    fonttitle=\bfseries,
    coltitle=black,
    title=File \thetcbcounter:\quad#2,
    blanker,
    #1
}

\newtcolorbox{auxfile}[2][]{%
    enhanced,
    fonttitle=\bfseries,
    coltitle=black,
    title=\phantom{File \thetcbcounter:\quad#2},
    blanker,
    #1
}

\tcbset{
    innerfile/.style={
        colframe=white,
        colback=blue!20,
        width=15cm,
        height=20cm,
        colbacktitle=black!50,
        fonttitle=\small\ttfamily,
        boxsep = 0pt,
        toptitle = 1mm,
        bottomtitle = 1mm,
        center title,
        title = {MWE\ [\imagepage]},
        graphics pages = {#1}
    }
}

\begin{document}

%\tcblistof{box}{List of boxes}

\begin{file}{One Page}
\tcbincludepdf[innerfile={1}]{1.pdf}
\end{file}

\foreach \i [count=\ni] in {1,3,6,7,...,9,12}{
    \ifnum\ni<2
        \begin{file}{Some Pages}        
        \tcbincludepdf[innerfile={\i}]{2.pdf}
        \end{file}
    \else
        \begin{auxfile}{Some Pages}
        \tcbincludepdf[innerfile={\i}]{2.pdf}
        \end{auxfile}
    \fi
}

\end{document}

enter image description here

5
  • Yes. This is a valid solution. There are only a couple of things to pay attention to. Please note that with the previous setup: (1) I was able to assign certain pages to include (for instance: {1-3,6-9,12} etc.) (2) I was able to add a TOC using: \renewcommand{\contentsname}{Files} \addtocontents{toc}{~\hfill\textbf{page}\par} \tcblistof[]{box}{} – Morzen Jan 7 at 17:33
  • @MorZahavi Something like {1-3,6-9,12} could be defined into a foreach command with {1,2,3,6,7,9,12}. For longer ranges you could do {1,2,...,5,6,...10,15,20}. The difference between the values before ... define the step to follow. You can find more information in TikZ documentation. – Ignasi Jan 8 at 18:47
  • @MorZahavi I've tried to find a solution for the listofboxes but I couldn't. The use of an external tcolorbox is valid, but the height of the title makes the first page go lower than following pages. If you can find how tall is the title box you could apply this shift to following boxes. Another solution could be to apply detach title in your external tcolorbox and later on use it as overlay like in my proposed solution. but I could find how to save the title and reuse into another tcolorbox. Maybe you can write some new questions with this particular problems. – Ignasi Jan 8 at 18:53
  • 1
    @MorZahavi I've proposed a second solution. I hope it's better. – Ignasi Jan 10 at 10:09
  • Great. It works. Could you please tell me how can I center the files to page center (in case I scale them, or use geometry)? – Morzen Jan 11 at 11:02

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.