tikzに関する質問です.

tikzに関する質問です.

- Edward Elric の投稿
返信数: 3
 tikzを使っていますが,図形の間に引く斜線の引き方がわかりません.

¥documentclass{jsarticle}
¥usepackage[top=30truemm,bottom=30truemm,left=25truemm,right=25truemm]{geometry}
¥usepackage{tikz}
¥usetikzlibrary{patterns}

% defining the new dimensions and parameters
¥newlength{¥hatchspread}
¥newlength{¥hatchthickness}
¥newlength{¥hatchshift}
¥newcommand{¥hatchcolor}{}
% declaring the keys in tikz
¥tikzset{hatchspread/.code={¥setlength{¥hatchspread}{#1}},
         hatchthickness/.code={¥setlength{¥hatchthickness}{#1}},
         hatchshift/.code={¥setlength{¥hatchshift}{#1}},% must be >= 0
         hatchcolor/.code={¥renewcommand{¥hatchcolor}{#1}}}
% setting the default values
¥tikzset{hatchspread=3pt,
         hatchthickness=0.4pt,
         hatchshift=0pt,% must be >= 0
         hatchcolor=black}
% declaring the pattern
¥pgfdeclarepatternformonly[¥hatchspread,¥hatchthickness,¥hatchshift,¥hatchcolor]% variables
   {custom north west lines}% name
   {¥pgfqpoint{¥dimexpr-2¥hatchthickness}{¥dimexpr-2¥hatchthickness}}% lower left corner
   {¥pgfqpoint{¥dimexpr¥hatchspread+2¥hatchthickness}{¥dimexpr¥hatchspread+2¥hatchthickness}}% upper right corner
   {¥pgfqpoint{¥dimexpr¥hatchspread}{¥dimexpr¥hatchspread}}% tile size
   {% shape description
    ¥pgfsetlinewidth{¥hatchthickness}
    ¥pgfpathmoveto{¥pgfqpoint{0pt}{¥dimexpr¥hatchspread+¥hatchshift}}
    ¥pgfpathlineto{¥pgfqpoint{¥dimexpr¥hatchspread+0.15pt+¥hatchshift}{-0.15pt}}
    ¥ifdim ¥hatchshift > 0pt
      ¥pgfpathmoveto{¥pgfqpoint{0pt}{¥hatchshift}}
      ¥pgfpathlineto{¥pgfqpoint{¥dimexpr0.15pt+¥hatchshift}{-0.15pt}}
    ¥fi
    ¥pgfsetstrokecolor{¥hatchcolor}
%    ¥pgfsetdash{{1pt}{1pt}}{0pt}% dashing cannot work correctly in all situation this way
    ¥pgfusepath{stroke}
   }
¥begin{document}
¥begin{tikzpicture}[domain=0:6]
¥coordinate (A) at (4.43,5.2); 
¥coordinate (B) at (2.9,1.9);
¥fill (A) circle (2pt) (B) circle (2pt); 
¥draw[->] (-1,0) -- (6.2,0);
¥draw[->] (0,-1) -- (0,6.2);
¥draw[->] (-1,0) -- (6.2,0);
¥draw (0,0) node[below left]{O};
¥draw[thick, domain=1:4.7,] plot (¥x,{0.05*exp(¥x)+1});
¥draw [thin, dashed](0,5.2)--(4.43,5.2)--(4.43,0)node[below]{$t+¥Delta t$}; 
¥draw [thin, dashed](0,1.9)--(2.9,1.9)--(2.9,0)node[below]{$t_0$}; 
¥draw [pattern=custom north west lines] (2.9,0) rectangle (4.43,1.9);
¥end{tikzpicture}
¥end{document}

上の図形で,(¥x,{0.05*exp(¥x)+1})の関数がありますが,その関数とx軸との間に斜線を引きたいです.(範囲は$t_0$から$t+¥Delta t$)その方法を教えてください.
Edward Elric への返信

Re: tikzに関する質問です.

- Edward Elric の投稿
¥usepackage[dvipdfmx]{graphicx}
¥usepackage[dvipdfmx,svgnames]{xcolor}

これを入れていませんでした.
Edward Elric への返信

Re: tikzに関する質問です.

- 飯島 徹 の投稿
次のような感じでしょうか?

\documentclass{jsarticle}
\usepackage[top=30truemm,bottom=30truemm,left=25truemm,right=25truemm]{geometry}
\usepackage[dvipdfmx]{graphicx}
\usepackage[dvipdfmx,svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{patterns}

% defining the new dimensions and parameters
\newlength{\hatchspread}
\newlength{\hatchthickness}
\newlength{\hatchshift}
\newcommand{\hatchcolor}{}
% declaring the keys in tikz
\tikzset{hatchspread/.code={\setlength{\hatchspread}{#1}},
hatchthickness/.code={\setlength{\hatchthickness}{#1}},
hatchshift/.code={\setlength{\hatchshift}{#1}},% must be >= 0
hatchcolor/.code={\renewcommand{\hatchcolor}{#1}}}
% setting the default values
\tikzset{hatchspread=3pt,
hatchthickness=0.4pt,
hatchshift=0pt,% must be >= 0
hatchcolor=black}
% declaring the pattern
\pgfdeclarepatternformonly[\hatchspread,\hatchthickness,\hatchshift,\hatchcolor]% variables
{custom north west lines}% name
{\pgfqpoint{\dimexpr-2\hatchthickness}{\dimexpr-2\hatchthickness}}% lower left corner
{\pgfqpoint{\dimexpr\hatchspread+2\hatchthickness}{\dimexpr\hatchspread+2\hatchthickness}}% upper right corner
{\pgfqpoint{\dimexpr\hatchspread}{\dimexpr\hatchspread}}% tile size
{% shape description
\pgfsetlinewidth{\hatchthickness}
\pgfpathmoveto{\pgfqpoint{0pt}{\dimexpr\hatchspread+\hatchshift}}
\pgfpathlineto{\pgfqpoint{\dimexpr\hatchspread+0.15pt+\hatchshift}{-0.15pt}}
\ifdim \hatchshift > 0pt
\pgfpathmoveto{\pgfqpoint{0pt}{\hatchshift}}
\pgfpathlineto{\pgfqpoint{\dimexpr0.15pt+\hatchshift}{-0.15pt}}
\fi
\pgfsetstrokecolor{\hatchcolor}
% \pgfsetdash{{1pt}{1pt}}{0pt}% dashing cannot work correctly in all situation this way
\pgfusepath{stroke}
}
\begin{document}
\begin{tikzpicture}[domain=0:6]
\coordinate (A) at (4.43,5.2);
\coordinate (B) at (2.9,1.9);
\fill (A) circle (2pt) (B) circle (2pt);
\draw[->] (-1,0) -- (6.2,0);
\draw[->] (0,-1) -- (0,6.2);
\draw[->] (-1,0) -- (6.2,0);
\draw (0,0) node[below left]{O};
\draw[thick, domain=1:4.7,] plot (\x,{0.05*exp(\x)+1});
\draw [thin, dashed](0,5.2)--(4.43,5.2)--(4.43,0)node[below]{$t+\Delta t$};
\draw [thin, dashed](0,1.9)--(2.9,1.9)--(2.9,0)node[below]{$t_0$};
%\draw [pattern=custom north west lines] (2.9,0) rectangle (4.43,1.9);
\fill[pattern=custom north west lines]plot[smooth,domain=2.9:4.43](\x,{0.05*exp(\x)+1})--(4.43,0)--(2.9,0);
\end{tikzpicture}
\end{document}