0

I'm pretty novice in LaTeX and use overleaf to write.

Is there any way that I could do this kind of box with a arbitrary text in it that is not linked to any title or chapter - just a black box with plain text in it?

I've tried to modify this code in the answer, but I only seem to break it...

How to make a chapter heading like this

Myggan
  • 3
  • \rule[-15pt]{2cm}{1.5cm}\llap{\color{white} III }

    Gets me closer, but can't really get it to appear at the very end of the side of the page

    – Myggan Dec 06 '18 at 10:12
  • \hspace{13.9cm}\raggedleft\rule[-15pt]{3cm}{1.5cm}\llap{\Huge\color{white} III }

    This seems to work, but seems like an ugly solution?

    – Myggan Dec 06 '18 at 10:24

1 Answers1

1

As you didn't specify your exact requirements, here's a simple ribbon version that puts a black box with white text to the left or right side of the paragraph text.

You can use \ribbonsep to specify the horizontal space between the text and the ribbon. A ribbon should always be used at the begin of a new paragraph, as it uses \noindent to get its placement right. That also means that you need to use \indent explicitly if the following paragraph text should be indented. Note that the code hasn't been tested much, so there are several chances for optimization/extensions here.

\documentclass{article}
\usepackage{lipsum}
\usepackage{xcolor}

\newlength\ribbonsep
\ribbonsep=12pt

\newcommand\ribbonleft{%
    \noindent
    \llap{%
        \smash{\vtop{%
            \kern-\baselineskip
            \hbox{\colorbox{black}{\makebox[\dimexpr 1in+\hoffset+\oddsidemargin-\ribbonsep][r]{%
                \Huge\textcolor{white}{\bfseries NOTE}%
                \rule[-5pt]{0pt}{\baselineskip}%
            }}}%
        }}%
        \hspace*{\ribbonsep}%
    }%
}

\newcommand\ribbonright{%
    \noindent
    \rlap{%
        \hspace*{\dimexpr\textwidth+\ribbonsep}%
        \smash{\vtop{%
            \kern-\baselineskip
            \hbox{\colorbox{black}{\makebox[\dimexpr 1in+\hoffset+\oddsidemargin-\ribbonsep][l]{%
                \Huge\textcolor{white}{\bfseries NOTE}%
                \rule[-5pt]{0pt}{\baselineskip}%
            }}}%
        }}%
    }%
}

\begin{document}
\lipsum[1]

\ribbonleft\indent
\lipsum[2]

\ribbonright\indent
\lipsum[3]
\end{document}

enter image description here

siracusa
  • 13,411