![tcolorbox:文本对齐问题](https://linux22.com/image/406150/tcolorbox%EF%BC%9A%E6%96%87%E6%9C%AC%E5%AF%B9%E9%BD%90%E9%97%AE%E9%A2%98.png)
我创建了 3 个 tcolorbox,一个在左,一个在右,一个在下。目的是让文本位于图表的左侧、右侧和下方(我添加了图表以便更好地解释。
我无法修复的问题是对齐。我希望文本在 3 种情况下对齐(左对齐、右对齐和下对齐),但我得到的只是左对齐的文本。
我希望这是有意义的,谢谢!
以下是代码:
\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{amsmath}
\usepackage{geometry}
\usepackage{hyperref}
\usepackage{lipsum}
\usepackage{float}
\usepackage{tikz}
\usetikzlibrary{babel}
\usetikzlibrary{arrows.meta,automata, decorations.pathreplacing}
\usepackage[most]{tcolorbox}
\usepackage{amsthm,amssymb,amsfonts}
\usepackage{tikz,lipsum,lmodern}
\usepackage{tabularx}
\usepackage{qrcode}
\usepackage{parskip}
\geometry{letterpaper, portrait, margin=1.3in}
% esto es para las cajas con los gráficos
\newtcolorbox[blend into=figures]{myfigureright}[2][]{%
float=htb!,blend before title=colon hang,colback=yellow!5!white,colframe=yellow!50!black,colbacktitle=yellow!75!black,title={#2},every float=\centering,halign=flush center,halign lower= left,sidebyside align=top seam,lower separated=false,sidebyside,righthand ratio=0.4, valign lower=top
#1}
\newtcolorbox[blend into=figures]{myfiguredown}[2][]{%
float=htb!,blend before title=colon hang,colback=yellow!5!white,colframe=yellow!50!black,colbacktitle=yellow!75!black,title={#2},halign=flush center,halign lower= left,lower separated=false, valign lower=top,
#1}
\newtcolorbox[blend into=figures]{myfigureleft}[2][]{%
float=htb!,blend before title=colon hang,colback=yellow!5!white,colframe=yellow!50!black,colbacktitle=yellow!75!black,title={#2},halign lower=center,halign=left,sidebyside align=top seam,lower separated=false,sidebyside,righthand ratio=0.666,
#1}
\title{book 1}
\author{jmv }
\date{\today}
\begin{document}
\maketitle
\tableofcontents
\chapter{graficos con texto abajo, izq, der}
\newpage
\begin{myfigureright}{RIGHT}
\begin{tikzpicture}[scale=0.04]
%titulo
\node [above] at (60,120) {$\textrm{Mercado de los lápices}$};
%ejes
\draw[very thick,<->] (0,120) node[above left]{$P$}--(0,0)--(150,0) node[below right]{$Q$};
%Curvas
\draw(0,100)--(100,0) node [right] at (90,10) {$Dda$};
\draw(20,0)--(120,100) node[right]{$Of$};
\end{tikzpicture}
\tcblower
Solución al equilibrio de mercado en el mercado de los lápices, representado por:
\begin{align*}
Q^D&=100-P\\
Q^O&=20+P
\end{align*}
\lipsum[1]
\end{myfigureright}
\begin{myfiguredown}{DOWN}
\begin{tikzpicture}[scale=0.04]
%titulo
\node [above] at (60,120) {$\textrm{Mercado de los lápices}$};
%ejes
\draw[very thick,<->] (0,120) node[above left]{$P$}--(0,0)--(150,0) node[below right]{$Q$};
%Curvas
\draw(0,100)--(100,0) node [right] at (90,10) {$Dda$};
\draw(20,0)--(120,100) node[right]{$Of$};
\end{tikzpicture}
\tcblower
Solución al equilibrio de mercado en el mercado de los lápices, representado por:
\begin{align*}
Q^D&=100-P\\
Q^O&=20+P
\end{align*}
\lipsum[1]
\end{myfiguredown}
\begin{myfigureleft}{LEFT}
Solución al equilibrio de mercado en el mercado de los lápices, representado por:
\begin{align*}
Q^D&=100-P\\
Q^O&=20+P
\end{align*}
\lipsum[1]
\tcblower
\begin{tikzpicture}[scale=0.04]
%titulo
\node [above] at (60,120) {$\textrm{Mercado de los lápices}$};
%ejes
\draw[very thick,<->] (0,120) node[above left]{$P$}--(0,0)--(150,0) node[below right]{$Q$};
%Curvas
\draw(0,100)--(100,0) node [right] at (90,10) {$Dda$};
\draw(20,0)--(120,100) node[right]{$Of$};
\end{tikzpicture}
\end{myfigureleft}
\end{document}
答案1
我发现了问题所在,我正在使用
halign=left,
这就是问题的原因。正如@David Carlisle所建议的,对齐是默认设置,所以我用这个命令覆盖了它。
感谢您的时间。
答案2
添加\justify{\lipsum[1]}
作品\usepackage{ragged2e}
来证明
\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{amsmath}
\usepackage{geometry}
\usepackage{hyperref}
\usepackage{lipsum}
\usepackage{float}
\usepackage{tikz}
\usetikzlibrary{babel}
\usetikzlibrary{arrows.meta,automata, decorations.pathreplacing}
\usepackage[most]{tcolorbox}
\usepackage{amsthm,amssymb,amsfonts}
\usepackage{tikz,lipsum,lmodern}
\usepackage{tabularx}
\usepackage{qrcode}
\usepackage{parskip}
\usepackage{ragged2e}
\geometry{letterpaper, portrait, margin=1.3in}
\newtcolorbox[blend into=figures]{myfiguredown}[2][]{%
float=htb!,blend before title=colon hang,colback=yellow!5!white,colframe=yellow!50!black,colbacktitle=yellow!75!black,title={#2},halign=flush center,halign lower= left,lower separated=false, valign lower=top,
#1}
\begin{document}
\begin{myfiguredown}{DOWN}
\begin{tikzpicture}[scale=0.04]
%titulo
\node [above] at (60,120) {$\textrm{Mercado de los lápices}$};
%ejes
\draw[very thick,<->] (0,120) node[above left]{$P$}--(0,0)--(150,0) node[below right]{$Q$};
%Curvas
\draw(0,100)--(100,0) node [right] at (90,10) {$Dda$};
\draw(20,0)--(120,100) node[right]{$Of$};
\end{tikzpicture}
\tcblower
Solución al equilibrio de mercado en el mercado de los lápices, representado por:
\begin{align*}
Q^D&=100-P\\
Q^O&=20+P
\end{align*}
\justify{\lipsum[1]}
\end{myfiguredown}
\end{document}