2

How do you fit the text in a fraction? I am trying to fit a text equation inside a colored box:

\documentclass[11pt,twoside, a4paper]{report}
\usepackage{fontspec}
\setmainfont{TeX Gyre Schola}
\usepackage[margin=0.75in]{geometry}
\usepackage{titlesec}
\usepackage{fancyhdr}
\usepackage{enumitem}
\usepackage{array}
\usepackage{pifont}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{amsmath}

\begin{document}

\tcolorbox[]{
\[
    v\textsubscript{tb} = \frac{\text{độ dài cung tròn mà vật đi được}}{\text{Thời gian chuyển động}}
\]

}

\end{document}

The thing is when I didn't use the \textsubscript and just used the math version v_{tb} the fractions perfectly aligns. What am I doing wrong?

Edit: I am only using the fraction for text not math, if anyone can find a better alternative please tell me.

5
  • I'm getting the following error message when I try to compile your code: "\begin{tcb@savebox} on input line 16 ended by \end{document}". Please fix.
    – Mico
    Commented Jan 9, 2022 at 10:31
  • 1
    why would you use \textsubscript in math?, that is certainly not as designed, even if it doesn't actually flag an error. Commented Jan 9, 2022 at 10:54
  • 1
    If you want to use text mode in a math environment you should insert it using \text{}
    – Imran
    Commented Jan 9, 2022 at 10:56
  • You should replace v\textsubscript{tb} with v_{\mathrm{tb}}.
    – Mico
    Commented Jan 9, 2022 at 12:33
  • How about putting the fomular in a TikZ's node?
    – Black Mild
    Commented Jan 9, 2022 at 14:56

3 Answers 3

0

The formula is inserted into a TikZ's node of a tikzpicture.

enter image description here

\documentclass{article}
\usepackage[utf8]{vietnam}
\usepackage{tikz,amsmath}
\usepackage{lipsum}
\begin{document}
\lipsum[2]  
\begin{center}
\begin{tikzpicture}
\node[draw,fill=yellow!50,rounded corners]
{$v_{\mathrm{tb}}=\dfrac{\text{độ dài cung tròn mà vật đi được}}
{\text{Thời gian chuyển động}}$};       
\end{tikzpicture}
\end{center}    
\lipsum[3]
\end{document}
1

Here's a solution that does not employ \textsubscript, uses LuaLaTeX, and uses the ebgaramond and ebgaramond-maths packages.

enter image description here

% !TEX TS-program = lualatex
\documentclass[11pt,twoside,a4paper]{report}
\usepackage[vietnamese]{babel}
\usepackage{amsmath} % for '\text' macro
\usepackage{ebgaramond,ebgaramond-maths}
\usepackage[most]{tcolorbox}
\begin{document}
\begin{tcolorbox}
\[
v_{\mathrm{tb}} = \frac{\text{độ dài cung tròn mà vật đi được}}{%
                        \text{Thời gian chuyển động}}
\]
\end{tcolorbox}
\end{document}
0

You should use a math subscript.

Also \tcolorbox{...} is wrong and the environment tcolorbox should be used. I suggest to use unicode-math and the Schola Math font. Alternatively, do \usepackage{fouriernc} before \usepackage{fontspec}.

\documentclass[11pt,twoside, a4paper]{report}
\usepackage{unicode-math}
\setmainfont{TeX Gyre Schola}
\setmathfont{TeX Gyre Schola Math}
\usepackage{amsmath}
\usepackage[most]{tcolorbox}

\begin{document}

\begin{tcolorbox}
\[
  v_{\mathrm{tb}} = \frac{\text{độ dài cung tròn mà vật đi được}}{\text{Thời gian chuyển động}}
\]
\end{tcolorbox}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .