5

I would like to get an output where I there is a box around the equation and text like this: enter image description here

I tried \mbox and \fbox but couldn't get it to work correctly. Thanks for your help!

CODE

\documentclass{article}
\usepackage[landscape]{geometry}
\usepackage{mathtools}
\usepackage{multicol}
\usepackage{amssymb,amsthm}
\usepackage{tikz}
\usetikzlibrary{tikzmark, quotes, decorations.pathmorphing, shapes, arrows.meta, positioning, calc}
\usepackage{pgfplots}
\usepackage{enumitem}
\usepackage[most]{tcolorbox}
\usepackage{booktabs}
\usepackage{float}
\usepackage{graphicx}

%======================================================================================
%   FOR TEXTBOX
%======================================================================================
\usepackage[pscoord]{eso-pic}
\newcommand{\placetextbox}[3]{% \placetextbox{<horizontal pos>}{<vertical pos>}{<stuff>}
  \setbox0=\hbox{#3}% Put <stuff> in a box
    \AddToShipoutPictureFG*
    {\put(\LenToUnit{#1\paperwidth},\LenToUnit{#2\paperheight}){\makebox[0pt][c]{\begin{tabular}{l}#3\end{tabular}}}}
  }%

\advance\topmargin-1in
\advance\textheight3in
\advance\textwidth3in
\advance\oddsidemargin-1.5in
\advance\evensidemargin-1.5in
\parindent0pt
\parskip2pt
\newcommand{\hr}{\centerline{\rule{3.5in}{1pt}}}

\begin{document}

\begin{multicols*}{3}

\newtcolorbox{mybox}[2][]{text width=0.97\textwidth,fontupper=\scriptsize,
fonttitle=\bfseries\sffamily\scriptsize, colbacktitle=black,enhanced,
attach boxed title to top left={yshift=-2mm,xshift=3mm},
boxed title style={sharp corners},top=3pt,bottom=2pt,
  title=#2,colback=white}


%-------------------ROOT LOCUS-----------------------------------
\begin{minipage}{0.4\textwidth}
\begin{mybox}{Root Locus Method - Analysis and Design}


Let: $G(s)=\frac{N_{1}}{D_{1}}$ and $H(s)=\frac{N_{2}}{D_{2}}$, then $\frac{C(s)}{R(s)}=\frac{K\frac{N_{1}(s)}{D_{1}(s)}}{1 + K\frac{N_{1}(s)}{D_{1}(s)}}=\frac{KN_{1}(s)D_{2}(s)}{D_{1}(s)D_{2}(s) + K N_{1}(s)N_{2}(s)}$

\placetextbox{0.35}{.965}{
\scriptsize{
Closed-Loop T.F.}}
\vspace*{0.3cm}

The poles of the Closed-Loop T.F. are the roots of $D_{1}(s)D_{2}(s) + K N_{1}(s)N_{2}(s)$
\end{mybox}
\end{minipage}
\end{multicols*}

\end{document}

Edit 1 Based on KJO suggestion, using the solutions posted to his directed website, I tried \tcbhighmath and this was the outcome:

enter image description here

Not what I was going for. Thanks!

Joe
  • 9,080
  • 1
    your requirement may (or may not) be similar to this answer https://tex.stackexchange.com/questions/280634/tikzmark-shadow-around-box/280734#280734 –  Oct 25 '18 at 15:50
  • @KJO, when I tried your suggestion, I now get that shown in the edited question. Is there a better solution? Thanks! – Joe Oct 27 '18 at 00:17
  • I agree that using that approach, I can only achieve similar misplacement so have to admit as a novice in these maters you need Super @marmot to take a look –  Oct 27 '18 at 16:36
  • 1
    Again it may not help but marmots recent answers to similar questions were https://tex.stackexchange.com/questions/450322/nested-boxes-around-a-few-items-in-an-itemize-environment and https://tex.stackexchange.com/questions/452323/tikz-nested-block-diagram-with-boxed-text-inside-other-blocks they may or may not help –  Oct 27 '18 at 19:30

1 Answers1

9

Here is a proposal based on the newest version of tikzmark and these nice tricks. The way you place the text may eventually lead to problems because the text is set via an overlay, i.e. it may run over the boundaries of the tcolorbox. On the other hand, \overset allows you to set the text over the fraction. Then all one needs to do is to pack the things that need to go in the box into \tikzmarknodes, and then draw the box via overlays. To have a blurred shadow I employed Paul Gaborit's nice tricks.

\documentclass{article}
\usepackage[landscape]{geometry}
\usepackage{mathtools}
\usepackage{multicol}
\usepackage{amssymb,amsthm}
\usepackage{tikz}
\usetikzlibrary{tikzmark,fit,backgrounds}
\usepackage{enumitem}
\usepackage[most]{tcolorbox}
\usepackage{booktabs}
\usepackage{ifthen}

% there is the wonderful geometry package which you are loading... 
% wanna have a look at it? this will allow you to replace the following lines by sth much nicer ;-)
\advance\topmargin-1in
\advance\textheight3in
\advance\textwidth3in
\advance\oddsidemargin-1.5in
\advance\evensidemargin-1.5in
\parindent0pt
\parskip2pt

% from https://tex.stackexchange.com/a/80207/121799
\tikzset{
  laser beam action/.style={
    line width=\pgflinewidth+.2pt,draw opacity=.1,draw=#1,
  },
  laser beam recurs/.code 2 args={%
    \pgfmathtruncatemacro{\level}{#1-1}%
    \ifthenelse{\equal{\level}{0}}%
    {\tikzset{preaction={laser beam action=#2}}}%
    {\tikzset{preaction={laser beam action=#2,laser beam recurs={\level}{#2}}}}
  },
  laser beam/.style={preaction={laser beam recurs={10}{#1}},draw opacity=1,draw=#1},
}
\begin{document}

\begin{multicols*}{3}

\newtcolorbox{mybox}[2][]{text width=0.97\textwidth,fontupper=\scriptsize,
fonttitle=\bfseries\sffamily\scriptsize, colbacktitle=black,enhanced,
attach boxed title to top left={yshift=-2mm,xshift=3mm},
boxed title style={sharp corners},top=3pt,bottom=2pt,
  title=#2,colback=white}


%-------------------ROOT LOCUS-----------------------------------
\begin{minipage}{0.4\textwidth}
\begin{mybox}{Root Locus Method - Analysis and Design}


Let: $ G(s)=\frac{N_{1}}{D_{1}}$ 
and $ H(s)=\frac{N_{2}}{D_{2}}$, 
then $ \frac{C(s)}{R(s)}=
\frac{K\frac{N_{1}(s)}{D_{1}(s)}}{1 + K\frac{N_{1}(s)}{D_{1}(s)}}=
\overset{\raisebox{3pt}{\scriptsize\tikzmarknode{text}{\text{Closed-Loop
T.F.}}}}{%
\tikzmarknode{frac}{\frac{KN_{1}(s)D_{2}(s)}{D_{1}(s)D_{2}(s) + K N_{1}(s)N_{2}(s)}}}$
\tikz[overlay,remember picture]{
\node[green!60!black,draw,thick,inner sep=1pt,fit=(text) (frac)](box){};
\begin{scope}[on background layer]
\draw[thin,laser beam=gray!50] ([xshift=2pt,yshift=-1.5pt]box.north west) rectangle 
([xshift=2pt,yshift=-1.5pt]box.south east);
\end{scope}}


The poles of the Closed-Loop T.F. are the roots of $D_{1}(s)D_{2}(s) + K N_{1}(s)N_{2}(s)$
\end{mybox}
\end{minipage}
\end{multicols*}

\end{document}

enter image description here

  • 1
    Yea! Your the marmot, I know I should not give thanks but you saved me trying out my hairbrained suggestions :-) –  Oct 28 '18 at 03:50