0

I am trying to create a colored box with some text in TikZ. Here is my dirty code:

\documentclass[a4paper,12pt]{extreport}
\usepackage{fontspec}
\usepackage{pgf}
\usetikzlibrary{calc}
\usepackage{lipsum}
\usepackage{color}
\begin{document}
\begin{tikzpicture}[every node/.style={inner sep=0pt}]
    \node[text width=15cm,align=center,fill=green](Text){%
        \lipsum[1-2]};
    \node[circle,draw=black,shift={(-1cm,1cm)},anchor=north west](CNW) at (Text.north west) {text};
    \node[circle,draw=black,shift={(1cm,1cm)},anchor=north east](CNE) at (Text.north east) {text};
    \node[circle,draw=black,shift={(-1cm,-1cm)},anchor=south west](CSW) at (Text.south west) {text};
    \node[circle,draw=black,shift={(1cm,-1cm)},anchor=south east](CSE) at (Text.south east) {text};
    \end{tikzpicture}
\end{document}

I am wondering how can I make the width of the node, which is labelled "Text", equal to \textwidth (whatever that number may be be in a document; the height of the node should accommodate any amount of text in it). The node should be centered on the page, however, when I try to put \textwidth in stead of 15cm, the picture goes off the page. Any suggestions are appreciated!

2
  • Please, give a code fully compilable. – AndréC Jul 1 '20 at 4:10
  • No problem with \node[text width=\textwidth,align=center,fill=green](Text){% \lipsum[1-2]};. – user31034 Jul 1 '20 at 9:04
2

Maybe you can consider tcolorbox for this kind of things. An example to produce something similar to the desired box is following. It needs to be adjusted and decide how to consider the space around the box but can give an idea.

\documentclass[a4paper,12pt]{extreport}
\usepackage{fontspec}
\usepackage{tikz}
\usetikzlibrary{calc, positioning}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\begin{document}
\begin{tcolorbox}[enhanced, colback=green!30,
    overlay={
        \node[circle,draw, above left=5mm of frame.north west] {text};
        \node[circle,draw, above right=5mm of frame.north east] {text};
        \node[circle,draw, below left=5mm of frame.south west] {text};
        \node[circle,draw, below right=5mm of frame.south east] {text};
    }
    ]
        \lipsum[1-2]
\end{tcolorbox}


\begin{tcolorbox}[enhanced, colback=green!30,
    width=10cm, center,
    overlay={
        \node[circle,draw, above left=5mm of frame.north west] {text};
        \node[circle,draw, above right=5mm of frame.north east] {text};
        \node[circle,draw, below left=5mm of frame.south west] {text};
        \node[circle,draw, below right=5mm of frame.south east] {text};
    }
    ]
        \lipsum[1-2]
\end{tcolorbox}
\end{document}

enter image description here

enter image description here

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.