How do I move an object over in a Horizontal Layout Group?

I want the right size of the speech bubble to change size depending on the length of the text.

The instructions I can find for how to do this tell you to make the text a child of the speech bubble, and then use a Layout Group. However, by doing this the text becomes stuck too far left.

How do I move it right?

Remove the Layout Group and Content Size Fitter from the bubble and add a Content Size Fitter to the Text.

Now add this Script to your bubble:

using TMPro;
using UnityEngine;

public class TMProParentScaler : MonoBehaviour
{
    public Vector2 bubbleMargin = new Vector2(50, 50);

    private RectTransform rectTransform;
    private RectTransform childTransform;

    private void Start()
    {
        rectTransform = GetComponent<RectTransform>();
        childTransform = rectTransform.GetChild(0).GetComponent<RectTransform>();
        //The line below will set the start size to the one of the first written text. You can remove this if you don't need it.
        childTransform.GetComponent<TextMeshProUGUI>().OnPreRenderText += _ => UpdateScaleOfTransform();
    }
    public void UpdateScaleOfTransform() //Call this from your script after changing the text!
    {
        Invoke(nameof(UpdateTheScale), .01f); //I need to wait that the text updates!
    }
    private void UpdateTheScale()
    {
        rectTransform.sizeDelta = childTransform.sizeDelta + bubbleMargin;
    }

    [ContextMenu("Test me in the inspector!")]
    public void Test()
    {
        childTransform.GetComponent<TextMeshProUGUI>().text = "Your dialogue";
        UpdateScaleOfTransform();
    }
}

Now, when you change the dialog remember to call the UpdateScaleOfTransform method of the bubble class you just made.

Since you asked for an autonomous solution this class is completely self dependent, no calls are made outside of it and no calls need to be made towards it.

using TMPro;
using UnityEngine;

public class TMProParentScaler : MonoBehaviour
{
    public Vector2 bubbleMargin = new Vector2(50, 50);

    private RectTransform rectTransform;
    private RectTransform childTransform;
    private TextMeshProUGUI childTextMesh;

    private void Start()
    {
        rectTransform = GetComponent<RectTransform>();
        childTransform = rectTransform.GetChild(0).GetComponent<RectTransform>();
        childTextMesh = childTransform.GetComponent<TextMeshProUGUI>();

        if (!childTextMesh) Debug.LogError("The dialogue bubble doesn't have a text as first child!!!");

        TMPro_EventManager.TEXT_CHANGED_EVENT.Add(ON_TEXT_CHANGED);
    }
    private void ON_TEXT_CHANGED(Object obj)
    {
        if (obj == childTextMesh)
            UpdateScaleOfTransform();
    }
    private void UpdateScaleOfTransform()
    {
        Invoke(nameof(UpdateTheScale), .01f); //I need to wait that the text updates!
    }
    private void UpdateTheScale()
    {
        rectTransform.sizeDelta = childTransform.sizeDelta + bubbleMargin;
    }

    [ContextMenu("Test me in the inspector!")]
    public void Test()
    {
        rectTransform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "Your dialogue";
        UpdateScaleOfTransform();
    }
}

@Patrickmol Thank you, that partially worked, but as you can see I’m having issues - the text isn’t displaying in the correct place and the bubble isn’t being scaled correctly.

Excuse me for the extreme response delay. I had to take a university exam. Here is the code adapting just on the X axis (width):

using TMPro;
using UnityEngine;

public class TMProParentScaler : MonoBehaviour
{
    public Vector2 bubbleMargin = new Vector2(50, 50);

    private RectTransform rectTransform;
    private RectTransform childTransform;
    private TextMeshProUGUI childTextMesh;

    private void Start()
    {
        rectTransform = GetComponent<RectTransform>();
        childTransform = rectTransform.GetChild(0).GetComponent<RectTransform>();
        childTextMesh = childTransform.GetComponent<TextMeshProUGUI>();

        if (!childTextMesh) Debug.LogError("The dialogue bubble doesn't have a text as first child!!!");

        TMPro_EventManager.TEXT_CHANGED_EVENT.Add(ON_TEXT_CHANGED);
    }
    private void ON_TEXT_CHANGED(Object obj)
    {
        if (obj == childTextMesh)
            UpdateScaleOfTransform();
    }
    private void UpdateScaleOfTransform()
    {
        Invoke(nameof(UpdateTheScale), .01f); //I need to wait that the text updates!
    }
    private void UpdateTheScale()
    {
        Vector2 targetSize =  rectTransform.sizeDelta; //I take the current size
        targetSize.x = childTransform.sizeDelta.x; //I just change the width
        rectTransform.sizeDelta = targetSize + bubbleMargin;
    }

    [ContextMenu("Test me in the inspector!")]
    public void Test()
    {
        rectTransform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "Your dialogue";
        UpdateScaleOfTransform();
    }
}