Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to put an optimization problem inside a box. After some research I found this method (please fill free to propose a better method if you know something better):

\documentclass[11pt,a4paper,twoside,openright]{report}

\usepackage{tikz}
\usepackage[T1]{fontenc} 
\usepackage[utf8]{inputenc}
\usepackage{color}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{verbatim}
\usepackage{caption}


\definecolor{mygray}{rgb}{0.9,0.9,0.9} % cyan
\tikzstyle{mybox} = [draw=black, fill=mygray!20, very thick,
    rectangle, rounded corners, inner sep=10pt, inner ysep=5pt]
\tikzstyle{fancytitle} =[draw=black,   thick, fill=white, text=black]

\usepackage{tikz}
\usepackage{pgfplots}


\captionsetup{font=scriptsize,labelfont=scriptsize}


\begin{document}
\section{Some Title}
Some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. 
\begin{tikzpicture}
\node [mybox] (box){%
\begin{minipage}{1.1\textwidth}
\begin{align}
 \label{eqn:LCP}
 \sum_{k \in A_b} \rho^b_k U_a(j,k) + r^a_j = v_a &\;&\;&  \forall j \in A_a, \forall a,b \in \Psi, b \neq a \\
 \sum_{j \in A_a} \rho^a_j = 1 &\;&\;& \forall a \in \Psi \\
 \rho^a_j \geq 0    &\;&\;& \forall j \in A_a, \forall a \in \Psi \\
 r^a_j \geq 0   &\;&\;& \forall j \in A_a, \forall a \in \Psi \\
 \label{eqn:LCPcomplementarity}
 \rho^a_jr^a_j = 0  &\;&\;& \forall j \in A_a, \forall a \in \Psi
\end{align}
\end{minipage}
};
\node[fancytitle, right=10pt] at (box.north west) {Some LCP};
\end{tikzpicture}

Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text.
\end{document}

However I want to position the box 5% left of the left margin of the text (as the box is 110% of text width).
If I try to use \begin{center} before \begin{tikzpicture} it seems not working as I want.

What can I do, then?

share|improve this question
1  
Welcome to TeX.SX! –  Adam Liter Feb 18 at 15:12
add comment

2 Answers

up vote 3 down vote accepted

You can use adjustbox like

\begin{adjustbox}{center}

content

\end{adjustbox}

Code:

\documentclass[11pt,a4paper,twoside,openright]{report}

\usepackage{tikz}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{color}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{verbatim}
\usepackage{caption}
\usepackage{adjustbox}


\definecolor{mygray}{rgb}{0.9,0.9,0.9} % cyan
\tikzstyle{mybox} = [draw=black, fill=mygray!20, very thick,
    rectangle, rounded corners, inner sep=10pt, inner ysep=5pt]
\tikzstyle{fancytitle} =[draw=black,   thick, fill=white, text=black]

\usepackage{tikz}
\usepackage{pgfplots}


\captionsetup{font=scriptsize,labelfont=scriptsize}


\begin{document}
\section{Some Title}
Some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text.

\begin{adjustbox}{center}
\begin{tikzpicture}
\node [mybox] (box){%
\begin{minipage}{1.1\textwidth}
\begin{align}
 \label{eqn:LCP}
 \sum_{k \in A_b} \rho^b_k U_a(j,k) + r^a_j = v_a &\;&\;&  \forall j \in A_a, \forall a,b \in \Psi, b \neq a \\
 \sum_{j \in A_a} \rho^a_j = 1 &\;&\;& \forall a \in \Psi \\
 \rho^a_j \geq 0    &\;&\;& \forall j \in A_a, \forall a \in \Psi \\
 r^a_j \geq 0   &\;&\;& \forall j \in A_a, \forall a \in \Psi \\
 \label{eqn:LCPcomplementarity}
 \rho^a_jr^a_j = 0  &\;&\;& \forall j \in A_a, \forall a \in \Psi
\end{align}
\end{minipage}
};
\node[fancytitle, right=10pt] at (box.north west) {Some LCP};
\end{tikzpicture}
\end{adjustbox}

Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text.
\end{document}

enter image description here

share|improve this answer
    
Thank you very much! The solution is very simple but if I had to learn it by myself it would have taken some hours or days! –  HAL9000 Feb 18 at 15:05
    
Excuse me, how can I install adjustbox? I downloaded it from ctan, I copied it into latex folder, I did latex adjustbox.ins but it complains about ydocstrip.tex. What's the correct way to install it? –  HAL9000 Feb 18 at 15:21
    
@HAL9000: Use your tex package manager. –  Harish Kumar Feb 18 at 15:26
1  
@HAL9000 The adjustbox package can be avoided by placing the tikzpicture in the following construct: \centering\makebox[0pt]{\begin{tikzpicture}...\end{tikzpicture}}\par. –  Steven B. Segletes Feb 18 at 16:05
1  
@HAL9000 Yes, I forgot... place a left brace { before the \centering and a right brace } after the \par. That will limit the extent of the \centering to the braced content. –  Steven B. Segletes Feb 18 at 17:04
show 4 more comments

Another attempt with tcolorbox with a counter and you can label it.

\documentclass[11pt,a4paper,twoside,openright]{report}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{color}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{verbatim}
\usepackage{caption}

\usepackage{tcolorbox}
\tcbuselibrary{skins,breakable}
\newcounter{example}
\newtcolorbox[use counter=example]{FancyTitle}[3][]{%
enhanced,colback=blue!10!white,colframe=orange,top=4mm,
enlarge top by=\baselineskip/2+1mm,
width=1.1\textwidth,
oversize,
enlarge top at break by=0mm,pad at break=2mm,
fontupper=\normalsize,label={#3},
overlay unbroken and first={%
\node[rectangle,rounded corners,draw=black,fill=green!30!white,
inner sep=1mm,anchor=west,font=\small]
at ([xshift=4.5mm]frame.north west)
{\strut\textbf{LCP \thetcbcounter: #2}};},
#1}%
%\begin{FancyTitle}{<title>}{<label>}
%<content>
%\end{FancyTitle}

\captionsetup{font=scriptsize,labelfont=scriptsize}


\begin{document}
\section{Some Title}
Some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text. some text.

\begin{FancyTitle}{Some LCP}{fancy:LCP}
\begin{align}
 \label{eqn:LCP}
 \sum_{k \in A_b} \rho^b_k U_a(j,k) + r^a_j = v_a &\;&\;&  \forall j \in A_a, \forall a,b \in \Psi, b \neq a \\
 \sum_{j \in A_a} \rho^a_j = 1 &\;&\;& \forall a \in \Psi \\
 \rho^a_j \geq 0    &\;&\;& \forall j \in A_a, \forall a \in \Psi \\
 r^a_j \geq 0   &\;&\;& \forall j \in A_a, \forall a \in \Psi \\
 \label{eqn:LCPcomplementarity}
 \rho^a_jr^a_j = 0  &\;&\;& \forall j \in A_a, \forall a \in \Psi
\end{align}
\end{FancyTitle}

Other text in LCP~\ref{fancy:LCP}. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text. Other text.
\end{document}

enter image description here

share|improve this answer
    
Now my answer seems redundant. I'll delete it. –  Gonzalo Medina Feb 18 at 15:32
    
@GonzaloMedina Oh No. I spent some time on this. Hence though I saw your answer, since mine had some extra features, I thought I will add it. Really sorry. :( –  Harish Kumar Feb 18 at 15:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.