# Positioning rasters using Tikz

I am trying to position a raster which span on multiple pages using tikz, but cannot figure out how to do so.

MWE without positioning which works:

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
%
\usepackage[raster,most]{tcolorbox}
\tcbset{
colorboxa/.style={
enhanced,
sharp corners,
breakable,
center,
boxrule=0.2mm,
colback=white,
colframe=black,
coltitle=black,
colbacktitle= white,
},}
%:colorboxa
% [1] Document Name
% [2] Document Label
\newtcolorbox[
auto counter,
list inside=files,
]{colorboxa}[2]{
colorboxa,
breakable,
colframe=blue,
boxrule=0.2mm,
raster columns=1,
list entry=File~\thetcbcounter: #1,
label={doc:#2},
nameref=#1,
}
%:rastera_environment
% [1] File Name
% [2] Document Name
% [3] Number of Pages
\newenvironment{rastera}[3]{
\begin{tcbraster}[
colorboxa,
colframe=red!80!black,
boxrule=0.2mm,
raster columns=1,
]
\tcbincludepdf[graphics pages={\x},]{#1.pdf}
\end{tcbraster}}{}
%:filea_environment
% [1] File Name
% [2] Number of Pages
% [3] Document Name
% [4] Label
\newenvironment{fileattach}[4]
{\noindent\ignorespaces
\vspace{10mm}
\begin{colorboxa}{#3}{#4}
\foreach \x in {1,...,#2}{
\begin{rastera}{#1}{#3}{#2}
\end{rastera}
}
\end{colorboxa}
}{}
\begin{document}
\tcblistof[]{files}{Files:} % TOC
% First attchment (1 page image)
\begin{fileattach}
{example-image}
{1} % Number of Pages
{Doc A} % Document Name
{doa} % Document Label
\end{fileattach}
% Second attchment (2 page document)
\begin{fileattach}
{example-image-letter-numbered}
{2} % Number of Pages
{Doc B} % Document Name
{dob} % Document Label
\end{fileattach}
\end{document}


MWE with Tikz positioning which does not work:

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
%
\usepackage[raster,most]{tcolorbox}
\tcbset{
colorboxa/.style={
enhanced,
sharp corners,
breakable,
center,
boxrule=0.2mm,
colback=white,
colframe=black,
coltitle=black,
colbacktitle= white,
},}
%:colorboxa
% [1] Document Name
% [2] Document Label
\newtcolorbox[
auto counter,
list inside=files,
]{colorboxa}[2]{
colorboxa,
breakable,
colframe=blue,
boxrule=0.2mm,
raster columns=1,
list entry=File~\thetcbcounter: #1,
label={doc:#2},
nameref=#1,
}
%:rastera_environment
% [1] File Name
% [2] Document Name
% [3] Number of Pages
\newenvironment{rastera}[3]{
\begin{tcbraster}[
colorboxa,
colframe=red!80!black,
boxrule=0.2mm,
raster columns=1,
]
\tcbincludepdf[graphics pages={\x},]{#1.pdf}
\end{tcbraster}}{}
%:filea_environment
% [1] File Name
% [2] Number of Pages
% [3] Document Name
% [4] Label
\newenvironment{fileattach}[4]
{\noindent\ignorespaces
\vspace{10mm}
\begin{colorboxa}{#3}{#4}
\foreach \x in {1,...,#2}{
\begin{tikzpicture}[remember picture,framed,overlay,]
\node [] at (current page.center)
[draw=red,anchor=center,scale=.5,]{
\begin{rastera}{#1}{#3}{#2}
\end{rastera}
};
\end{tikzpicture}
}
\end{colorboxa}
}{}
\begin{document}
\tcblistof[]{files}{Files:} % TOC
% First attchment (1 page image)
\begin{fileattach}
{example-image}
{1} % Number of Pages
{Doc A} % Document Name
{doa} % Document Label
\end{fileattach}
% Second attchment (2 page document)
\begin{fileattach}
{example-image-letter-numbered}
{2} % Number of Pages
{Doc B} % Document Name
{dob} % Document Label
\end{fileattach}
\end{document}


• If I'm not wrong, your fileattach command declares a tcolorboxwhich includes a tikzpicture which includes a tcbraster (which is a collection of tcolorboxes). I think it's too much nesting. Why don't you explain what do you want to obtain? probably there are better solutions. To me it seems that you want to center boxed images in independent pages, why do you need a tcbraster? Feb 19 at 16:15
• A node is not breakable, it's an indivisible box while a tcbraster is breakable by definition. Therefore a node can only contain tcbrasters which are not broken between pages. I even don't know if nodes can contain non broken tcbrasters. I still think that the solution proposed in tex.stackexchange.com/a/577943/1952 is better. If you want external borders, different titles, ... It's possible to add them. But please, explain it better. Feb 19 at 16:31
• My aim is to control the exact absolute positioning of each raster in each page. The reason for that is that I want to be able to control rasters (which may contain pdf pages or images of different sizes) position in the document. Without the ability to control attachments' position, I will not be able to distribute attachments in a structured manner throughout the document. My final aim is to develop a package out of this template. Feb 20 at 5:55
• The solution offered here tex.stackexchange.com/questions/577339/… does not allow for positioning at all. Moreover, the present question has added another requirement - each raster must include the following information: Attachment number, Attachment name, current page, total pages of the Attachment. Feb 20 at 6:06

I will insist with the solution provided in Unequal height with \tcbincludepdf raster, i.e., forget rasters and print every page with an independent tcolorbox.

I don't know what OP really wants, he/she says (in comments) I want to be able to control rasters (which may contain pdf pages or images of different sizes) position in the document. Without the ability to control attachments' position, I will not be able to distribute attachments in a structured manner throughout the document.

All examples provided in this question and previous ones, only mention centering one individual figure/text on a page, nothing about several boxes on same page. Therefore I don't understand why a tcbraster is needed.

To my understanding, tcolorboxes cannot be placed on specific positions unless they are included into a TiKZ node. tcbrasters only provide a regular distribution of boxes but they cannot be placed into a node unless they are unbreakable.

A tcolorbox can clearly position boxes over a desired position but a tcbposter is unbreakable and it would be necessary to declare a tcbposter for every page.

Following code shows a solution to include one single tcolorbox which includes one single image/page/text into one page. This boxes are vertically and horizontally centered with help of options before and after.

Problems for referencing them and building a list of files have been resolved like in previous question. The first included image from every file is added to the list of files, while other pages are included into another kind of box which is not listed although it keeps title, pages, ...

May be this code could be simplified or it doesn't solve all problems, but to improve it I need to understand what's the real problem to be solved or an example of what should be the desired result.

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usepackage{lipsum}
%
\usepackage[raster,most]{tcolorbox}

\newcounter{mycounter}
%:colorboxa
% [1] Document Name
% [2] Document Label
% [3] Document page
% [4] Total pages
\newtcolorbox[use counter=mycounter, list inside=files,]{colorboxa}[4]{%
enhanced,
sharp corners,
center, halign=center,
colframe=red!80!black, coltitle=black, colbacktitle= white,
colback=white, boxrule=0.2mm,
borderline={0.2mm}{-3 mm}{blue}, width=\linewidth-6mm, enlarge by=3mm,
list entry=File~\thetcbcounter: #1,
label={doc:#2},
nameref=#1,
before=\vfill\centering, after=\vfill\newpage,
}

%:colorboxb
% [1] Document Name
% [2] Document Label
% [3] Document page
% [4] Total pages
\newtcolorbox{colorboxb}[4]{%
enhanced,
sharp corners,
center, halign=center,
colframe=red!80!black, coltitle=black, colbacktitle= white,
colback=white, boxrule=0.2mm,
borderline={0.2mm}{-3 mm}{blue}, width=\linewidth-6mm, enlarge by=3mm,
before=\vfill\centering, after=\vfill\newpage,
}

%:filea_environment
% [1] File Name
% [2] Number of Pages
% [3] Document Name
% [4] Label
\newcommand{\fileattach}[4]
{%
\foreach \x [count=\nx] in {1,...,#2}{%
\ifnum\nx<2
\begin{colorboxa}{#1}{#3}{\x}{#2}
\includegraphics[page={\x}, width=\linewidth]{#1.pdf}
\end{colorboxa}
\else
\begin{colorboxb}{#1}{#3}{\x}{#2}
\includegraphics[page={\x}, width=\linewidth]{#1.pdf}
\end{colorboxb}
\fi}}

\begin{document}
\tcblistof[]{files}{Files:} % TOC
%% First attchment (1 page image)

\fileattach{example-image}
{1} % Number of Pages
{Doc A} % Document Name
{doa} % Document Label
%% Second attchment (2 page document)
\fileattach
{example-image-letter-numbered}
{3} % Number of Pages
{Doc B} % Document Name
{dob} % Document Label
\fileattach
{example-image-letter-numbered}
{2} % Number of Pages
{Doc C} % Document Name
{dob} % Document Label
\end{document}


• You are right in that I did not show multiple (smaller) figures in the same page, but it is one of the features I need. The TOC has to differentiate between: (1) Files spanning multiple pages, and (2) Files which contain multiple figures at the same page. Feb 28 at 9:26