[카테고리:] Latex

  • Write an equation in Latex

    (1) Basic

    \begin{align}
        y = f(x) \\ %automatically numbering, "\\" means "change the line"
        y = g(x) \nonumber \\ % "\nonumber" means "do not numbering this equation"
        y = \frac{1}{x} \nonumber
    \end{align}

    (2) Alignment

    \begin{align}
        y &= f(x) \nonumber \\
        &= T_{0}+ (T_{0}-T_{h})e^{-x} % "&"s are automatically aligned them among themselves.
    \end{align}
  • Draw a graph in latex

    (e.g.1) Simple example: y=1-x

    \documentclass[tikz,border=10pt]{standalone} %border: 여백 추가 (현재 상하좌우 10pt)
    \usepackage{tikz}
    \usepackage{amsmath} % 수식 표현을 위한 패키지
    \usetikzlibrary{patterns}
     
    \begin{document}
     
    \begin{tikzpicture}[scale=4]
        % Draw axes
        \draw[->] (-0.2, 0) -- (2.1, 0) node[right] {$x_1$};
        \draw[->] (0, -0.2) -- (0, 2.1) node[above] {$x_2$};
     
        \draw[thick] (1, 0.02) -- (1, -0.02) node[below left] {$1$}; % x1-axis intersection
        \draw[thick] (-0.02, 1) -- (0.02, 1) node[below left] {$1$}; % x2-axis intersection
         
        \draw[dashed] (1, -0.2) -- (1, 1.9) node[right] {};
        \draw[dashed] (-0.2, 1) -- (1.9, 1) node[right] {};
        \draw[thick, gray , domain=0:2, samples=100]
            plot(\x, {2 -\x})
            node[yshift=1.5cm]{$x_1+x_2<2$};
     
        \fill[pattern=north east lines, pattern color=gray, opacity=0.7]
            (0, 1) -- (1, 0) -- (1, 1) -- cycle;
     
        \fill[blue] (1, 1) circle (0.5pt) 
         
        \draw[thick, blue, domain=-0.2:1.3, samples=100] 
            plot (\x, {1 - \x}) ;
             
        \node[below left] at (0, 0) {$(0, 0)$};
    \end{tikzpicture}
     
    \end{document}

    (e.g.2) More complicated example

    \documentclass[tikz,border=10pt]{standalone} %border: 여백 추가 (현재 상하좌우 10pt)
    \usepackage{tikz}
    \usepackage{amsmath} % 수식 표현을 위한 패키지
    \usetikzlibrary{patterns}
     
    \begin{document}
     
    \begin{tikzpicture}[scale=4]
        % Draw axes
        \draw[->] (-0.2, 0) -- (2.1, 0) node[right] {$x_1$};
        \draw[->] (0, -0.2) -- (0, 2.1) node[above] {$x_2$};
     
        \draw[thick] (1, 0.02) -- (1, -0.02) node[below left] {$1$}; % x1-axis intersection
        \draw[thick] (-0.02, 1) -- (0.02, 1) node[below left] {$1$}; % x2-axis intersection
         
        \draw[dashed] (1, -0.2) -- (1, 1.9) node[right] {};
        \draw[dashed] (-0.2, 1) -- (1.9, 1) node[right] {};
        \draw[thick, gray , domain=0:2, samples=100]
            plot(\x, {2 -\x})
            node[yshift=1.5cm]{$x_1+x_2<2$};
     
        \fill[pattern=north east lines, pattern color=gray, opacity=0.7]
            (0, 1) -- (1, 0) -- (1, 1) -- cycle;
     
        \fill[blue] (1, 1) circle (0.5pt) 
        node[above right,scale=0.8]{soft};
         
        \draw[thick, blue, domain=-0.2:1.3, samples=100] 
            plot (\x, {1 - (0^2) - \x}) ;
     
        \draw[thick, red, domain=-0.2:1, samples=100]
            plot(\x, {1 - (0^2) / (1-\x)})
            node[above, xshift=-2cm, yshift=0cm,scale=0.8] {collinear};
        \draw[thick, red, domain=-0.2:1, samples=100]
            plot(1, \x)
            node[right, xshift=0cm, yshift=-2cm,scale=0.8] {collinear};
     
        \node[below left] at (0, 0) {$(0, 0)$};
    \end{tikzpicture}
     
    \end{document}

    (e.g.3) More more complicated example

    \documentclass[tikz,border=10pt]{standalone} %border: 여백 추가 (현재 상하좌우 10pt)
    \usepackage{tikz}
    \usepackage{amsmath} % 수식 표현을 위한 패키지
    \usetikzlibrary{patterns}
     
    \begin{document}
     
    \begin{tikzpicture}[scale=4]
        % Draw axes
        \draw[->] (-0.2, 0) -- (2.1, 0) node[right] {$x_1$};
        \draw[->] (0, -0.2) -- (0, 2.1) node[above] {$x_2$};
     
        \draw[thick] (0.75, 0.02) -- (0.75, -0.02) node[below] {$1 - \frac{\mu^2}{s}$}; % x1-axis intersection
        \draw[thick] (-0.02, 0.75) -- (0.02, 0.75) node[left] {$1 - \frac{\mu^2}{s}$}; % x2-axis intersection
        \draw[dashed] (1, -0.2) -- (1, 1.9) node[right] {};
        \draw[dashed] (-0.2, 1) -- (1.9, 1) node[right] {};
        \draw[thick, gray , domain=0:2, samples=100]
            plot(\x, {2 -\x})
            node[yshift=1.5cm]{$x_1+x_2<2$};
     
        \fill[pattern=north east lines, pattern color=gray, opacity=0.7]
            plot[domain=0:0.75, samples=100] (\x, {1 - (0.5^2) - \x}) --
            plot[domain=0.75:0, samples=100] (\x, {1 - (0.5^2) / (1-\x)}) -- cycle;
         
        % First equation: x_1 + x_2 = 1 - \mu^2 / s
        \draw[thick, blue, domain=-0.2:1.3, samples=100] 
            plot (\x, {1 - (0.5^2) - \x}) 
            node[below right, xshift=-0.2cm, yshift=0.8cm,scale=0.6] {$z=+1:x_1 + x_2 = 1 - \frac{\mu^2}{s}$};
     
        % Second : (1-x_1)(1-x_2) = \mu^2 / s
        \draw[thick, red, domain=-0.2:0.8, samples=100]
            plot(\x, {1 - (0.5^2) / (1-\x)})
            node[above right, xshift=-1.5cm, yshift=3.5cm,scale=0.6] {$z=-1:(1-x_1)(1-x_2) =\frac{\mu^2}{s}$};
     
        \draw[thick, red, domain=1.3:1.95, samples=100]
            plot(\x, {1 - (0.5^2) / (1-\x)});
     
        % Third : z=0.5 case
        \draw[dashed, domain=-0.2:1, samples=100]
            plot(\x, { ( \x - (1-0.25) )/ (0.25 * \x - 1) });
        \draw[dashed, domain=-0.2:1, samples=100]
            plot(\x, { ( \x - (1-0.25) )/ (0.5*(1-0.1) * \x - 1) });
        \draw[dashed, domain=-0.2:1, samples=100]
            plot(\x, { ( \x - (1-0.25) )/ (0.5*(1+0.3) * \x - 1) });
        \draw[dashed, domain=-0.2:0.9, samples=100]
            plot(\x, { ( \x - (1-0.25) )/ (0.5*(1+0.7) * \x - 1) });
         
        % Add origin
        \node[below left] at (0, 0) {$(0, 0)$};
    \end{tikzpicture}
     
    \end{document}
    
  • How to insert a figure?

    (Optional) Upload your image file on your overleaf cloud

    \begin{figure}[h!]
        \centering
        \includegraphics[width=0.5\textwidth]{Figures/figure1.pdf}
        \caption{Caption}
    \end{figure}
    \FloatBarrier %(Optional) This line prevents the pictures from being placed in an order I didn't intend.
    
  • Overleaf Pre-Setting

    (1) main.tex (Just copy the below codes, and paste on your main.tex file. You may need to press enter a bit)

    \documentclass[10pt]{article}
    \usepackage{graphicx} % 그림 삽입하기 위한 패키지
    \usepackage{indentfirst}
    \usepackage{subfiles} % 하위 파일 지원 패키지
    \usepackage{subcaption}
    \usepackage{amsfonts} % 폰트 추가
    \usepackage{amsmath} % 수식 추가
    \usepackage{amssymb} % math 심볼 추가
    \usepackage{cancel} % 슬래쉬 치기
    \usepackage{hyperref} % 수식 참조 및 하이퍼링크
    \usepackage[most]{tcolorbox} % 수식 박스안에
    \usepackage{placeins}
    \tcbuselibrary{listingsutf8} % 박스 사이즈 조절, 위 여백은 -3mm , 아래여백 1mm
    \usepackage{tikz}
     
    \newcommand*\circled[1]{\tikz[baseline=(char.base)]{
    \nodeshape=circle,draw,inner sep=0.5pt {#1};}}
    \DeclareMathSymbol{\mlq}{\mathrel}{operators}{"5C} % left-double-quotation
    \DeclareMathSymbol{\mrq}{\mathrel}{operators}{`"} % right-double-qutotation
     
    \usepackage{geometry}
    \geometry{
    a4paper,
    total={170mm,257mm},
    left=20mm,
    top=20mm,
    }
    \setlength{\parindent}{5pt} %인덴테이션 조절
     
    \title{blank project}
    \author{Do-Hyun Song}
    \date{March 2025}
     
    \begin{document}
     
    \maketitle
     
    \subfile{Sections/sec1.tex} % sec1.tex 불러오기 (폴더가 같은 위치에 있으면 상위폴더 지정 필요X)
    \subfile{Sections/sec2.tex}
    \subfile{Sections/sec3.tex}
     
    \bibliographystyle{unsrt}
    \bibliography{ref}
     
    \end{document}

    (2) sec1.tex (subsection file)

    \documentclass[../main.tex]{subfiles} %main.tex의 프리앰블 설정 상속받기
    \begin{document} % 단독 컴파일 가능
     
    \section{Section 1} %섹션 제목 입력
     
    Hello, World! %begin{document}-end{document} 사이에 글을 작성
     
    \end{document}