2

I have a one-page standalone document:

\documentclass[border=1pt]{standalone}
\begin{document}
Lorem ipsum
\end{document}

I would like to create a command \removeborder that will, when placed between the \begin{document} and \end{document} commands, remove the border from this one-page document.

\documentclass[border=1pt]{standalone}
\newcommand{\removeborder}{???}
\begin{document}
\removeborder
Lorem Ipsum
\end{document}

While \standaloneconfig{border=0pt} (documented here) is similar to what I want, when put in place of the ???, it does not remove the border from the page. Unfortunately, I am rather restricted on which parts of this code I can modify, thus why I do not modify the \documentclass statement. The command \removeborder will always be called from within the page it should affect; I cannot simply define a \standaloneenv and place \removeborder before the environment is entered.

My question: What can I place in the ??? in the second code block to remove the border from this document?

5
  • 1
    why don't use \standaloneconfig{border=0pt} before \begin{document}?
    – touhami
    Oct 8, 2017 at 8:02
  • I realize that I could, however the point of this question is to make a command so that I can change it after \begin{document}. I intend to use it in an application that gives me only limited control over the LaTeX header and footer, but much more control over the body.
    – Dragon
    Oct 8, 2017 at 8:09
  • I think there is no automatic page break with standalone (each page is a block or environment) so you can add your command just before this block.
    – touhami
    Oct 8, 2017 at 8:42
  • Do you mean \documentclass[border=1pt]{standalone}\standaloneconfig{border=0pt}\begin{document}Lorem Ipsum\end{document}? If so, this is not what I seek; I wish to define a command that I can call between \begin{document} and \end{document} that will remove the border on that page.
    – Dragon
    Oct 8, 2017 at 8:49
  • I mean you can get your wish but only from next page and this should not be a problem because we know pages break points
    – touhami
    Oct 8, 2017 at 8:54

2 Answers 2

1

The border values (one per side) are stored internally as \sa@border@left etc. by standalone. There are then applied (using \marginbox by my other package adjustbox) to the content box after the box is processed but before it is typeset. You can therefore change the values inside the content, however because it is grouped the changes will be lost at the end if the changes are not made global.

Note that the standard border is 0.50001 bp (big points, 72bp = 72.27pt), not 0 as this would visiually cut the text a little.

So the solution is:

\documentclass[border=1pt]{standalone}

\makeatletter
\newcommand{\removeborder}{%
    \global\def\sa@border@left{0.50001bp}%
    \global\let\sa@border@right\sa@border@left
    \global\let\sa@border@top\sa@border@left
    \global\let\sa@border@bottom\sa@border@left
}
\makeatother

\begin{document}
\removeborder
Lorem Ipsum
\end{document}
0

Here is a try.

With standalone class the start and the end of each page is clear (environment) and i think there is no automatic page break so one can add command that change border just before the page.

\documentclass[tikz,border=1cm]{standalone}
\makeatletter %save current values of border
\edef\mysaborders{\sa@border@left\space\sa@border@right\space\sa@border@top\space\sa@border@bottom}
\makeatother
\newcommand{\removeborder}{%
\standaloneconfig{border=0pt}}

\newcommand{\resetborder}{%
\standaloneconfig{border={\mysaborders}}}



\begin{document}
\begin{tikzpicture}
\fill[red!20](0,0) rectangle (3,3);
\end{tikzpicture}
\removeborder
\begin{tikzpicture}
\fill[red!60](0,0) rectangle (3,3);
\end{tikzpicture}

\begin{tikzpicture}
\fill[blue!60](0,0) rectangle (3,3);
\end{tikzpicture}

\resetborder
\begin{tikzpicture}
\fill[red!20](0,0) rectangle (3,3);
\end{tikzpicture}
\end{document}
4
  • The command must be called within the bounds of a page, and remove the borders of that page; eg., in your example, moving \removeborder up two lines should remove the border of the first page. Sorry for the miscommunication; I will clarify the text of the question.
    – Dragon
    Oct 8, 2017 at 9:29
  • why you can't move it before the first \begin{tikzpicture}?
    – touhami
    Oct 8, 2017 at 9:42
  • I am going to be using this in an application that does not give me complete control over the entire LaTeX document; the \removeborder command will always be called from within any \standaloneenv in the document. Essentially, Lorem Ipsum in the example will be replaced with arbitrary (but sensible-ish) LaTeX code from somewhere, and it should not have to specify all of\mayberemoveborder\begin{...}Lorem Ipsum\end{...}, but rather just \mayberemoveborder Lorem Ipsum.
    – Dragon
    Oct 8, 2017 at 9:52
  • you can build a solution that need two runs
    – touhami
    Oct 8, 2017 at 9:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .