Drawing TikZ box equal to the textwidth
You have set the inner sep = 10pt
, so you should subtract double that value from the width of the minipage
, besides \noindent
is also required.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,decorations}
\usepackage{amsmath,amssymb}
\usepackage{showframe}
\begin{document}
\tikzstyle{mybox} = [draw=red, fill=blue!20, very thick,
rectangle, rounded corners, inner sep=10pt, inner ysep=20pt]
\tikzstyle{fancytitle} =[fill=red, text=white]
\noindent\begin{tikzpicture}
\node [mybox] (box){%
\begin{minipage}{\dimexpr\textwidth-20pt}
Some text and math blah blah blah
\begin{align}
\dot{n} &= u\cos\psi -v\sin\psi \\
\dot{e} &= u\sin\psi + v\cos\psi
\end{align}
\end{minipage}
};
\node[fancytitle, right=10pt] at (box.north west) {A fancy title};
\node[fancytitle, rounded corners] at (box.east) {$\clubsuit$};
\end{tikzpicture}%
\end{document}
A tcolorbox
is, by default, as wide as \textwidth
, so you don't have to worry about its size and placement.
\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{amsmath,amssymb}
\usepackage{showframe}
\newtcolorbox{mybox}[2][]{%
enhanced,
title = #2,
attach boxed title to top left={%
xshift=5mm,
yshift=-\tcboxedtitleheight/2,
yshifttext=-1mm},
boxed title style={colback=red, sharp corners},
colframe = red,
colback = blue!20,
overlay = {\node[text=white, fill=red] at (frame.east)
{$\clubsuit$};},
#1}
\begin{document}
\begin{mybox}{A fancy title}%
Some text and math blah blah blah
\begin{align}
\dot{n} &= u\cos\psi -v\sin\psi \\
\dot{e} &= u\sin\psi + v\cos\psi
\end{align}
\end{mybox}
\end{document}